Google Colab: problems to run fig.write_image()

Viewed 1597

I am trying to save a plotly line static image using the next code:

import plotly 
import plotly.express as px
fig = px.line(EFBCg_f[1:12], x='time(ms)', y="C(n)", width=800, height=200)
fig.show()
file='Results/filename.png'
fig.write_image(file)

in the site https://plotly.com/python/static-image-export/, marks as a request to install eithe:

!pip install -U kaleido

or

conda install -c plotly python-kaleido

I do not have problems to install kaleido using pip, but create an empty file.

Therefore, I try to install kaleido using coda, but first I have to install coda because it is not native in Google Colab. I proceed as follows:

!pip install conda

and I do not have problems. Then, I run the command:

!conda install -c plotly python-kaleido

and I have the next reply:

ERROR: The install method you used for conda--probably either `pip install conda`
or `easy_install conda`--is not compatible with using conda as an application.
If your intention is to install conda as a standalone application, currently
supported install methods include the Anaconda installer and the miniconda
installer.  You can download the miniconda installer from
https://conda.io/miniconda.html.

now, I stuck.

I appreciate if you can help to find the problem. Thank you. Juan.

2 Answers

To save an image from plotly in Google Colab first run:

!pip install -U kaleido

Then go to Runtime > Restart Runtime in the menu.

After restarting runtime, re-run your code. (You don't need to rerun the pip command).

See this discussion for why Restart Runtime is sometimes needed to install a package in Google Colab.

try this (tnx to Greg Hogg https://youtu.be/qNF1HqBvpGE)

!wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -O /usr/local/bin/orca

!chmod +x /usr/local/bin/orca

!apt-get install xvfb libgtk2.0-0 libgconf-2-4
Related