Skip to content

Fix kaleido image export bug #2228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2023

Conversation

quinten-goens
Copy link
Contributor

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

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
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