Skip to content

Fix kaleido image export bug - #2228

Merged
cpsievert merged 1 commit into
plotly:masterfrom
quinten-goens:fix/kaleido-export-bug
Feb 13, 2023
Merged

cpsievert merged 1 commit into
plotly:masterfrom
quinten-goens:fix/kaleido-export-bug

Conversation

@quinten-goens

@quinten-goens quinten-goens commented Jan 30, 2023 •

Copy link
Copy Markdown
Contributor

Description of the problem

The code needs access to the Python sys module to run. Otherwise it gives a missing package error. The following code generates the error:

# Install latest development version
devtools::install_github("ropensci/plotly")

# Import libraries
library(plotly)
library(reticulate)

# Create example plot
fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")

# Simulate a conda environment to use Kaleido
reticulate::install_miniconda()
reticulate::conda_install('r-reticulate', 'python-kaleido')
reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')
reticulate::use_miniconda('r-reticulate')

# Save the figure
save_image(fig,file="image.png", height=500, width=700)

The error is:

> save_image(fig,file="image.png", height=500, width=700)
Error in py_run_string_impl(code, local, convert) : 
  NameError: name 'sys' is not defined

This has been solved by importing the sys package in the Python command in the correct place, see commit.

Installing the bugfix

You can install the version with the bugfix and rerun the code like this:

# Reinstall latest development version which includes the bugfix
devtools::install_github("quinten-goens/plotly.R@fix/kaleido-export-bug")

# Import libraries
library(plotly)
library(reticulate)

# Create example plot
fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")

# Simulate a conda environment to use Kaleido
reticulate::install_miniconda()
reticulate::conda_install('r-reticulate', 'python-kaleido')
reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')
reticulate::use_miniconda('r-reticulate')

# Save the figure
save_image(fig,file="image.png", height=500, width=700)

The export works now.

The line needs access to the Python sys module to run. Otherwise it gives a missing package error.
@cpsievert

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants