plotly-resampler: FigureWidget(Resampler) does not integrate well in google colab

In google colab plotly FigureWidget & plotly-resampler FigureWidgetResampler:

πŸŽ‰ work perfectly when creating an empty figure and displaying it while adding traces in another cell

Example with plotly FigureWidget:

image

Example with plotly-resampler FigureWidgetResampler:

image

😿 do not work when creating the figure and adding the data + displaying it in the same cell

Example for plotly FigureWidget & plotly-resampler FigureWidgetResampler

image

-> This relates to this issue; https://github.com/googlecolab/colabtools/issues/2871 (however for FigureWidgetResampler it does not work for integer datatypes, whereas for FigureWidget this does work)

What is the impact of this problem?

Registing plotly-resampler in google colab will result in figures that are not displayed;

image


FYi: to use plotly FigureWidgets in google colab you should first execute the following code (see __init__.py);

from google.colab import output
output.enable_custom_widget_manager()

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Hey @LeonieFreisinger,

Thanks for sharing the notebook & the detailed explanation! I was able to reproduce your issue.

I (quickly) succeeded to get a functional interactive plot by using the FigureResampler (which uses a Dash application instead of an IPython FigureWidget to provide the resampling) instead of the FigureWidgetResampler. However, note that the rendering of the plot takes some additional time (as Google has to sort out the portforwarding of the underlying (Jupyter)Dash app) - locally (or on your own server) the plot should be rendered nearly instantaneous.

You can use the FigureResampler decorator (under the hood) through calling register_plotly_resampler with the β€œfigure” mode.

register_plotly_resampler(mode="figure")

See working example below ⬇️

image

❗ Currently, plotly-resampler does not properly suppoty rangeslider https://github.com/predict-idlab/plotly-resampler/issues/156 (however, @jonasvdd is currently looking into this)

I’ll share my further findings in this Issue (I’ll investigate FigureWidgetResampler now).

Cheers, Jeroen

@jvdd Thanks for your fast answer. I will have a more detailed look into it and get back to you asap.

@jvdd @jonasvdd Thanks for the quick feedback! I will have a look at it and get back to you shortly.

I further looked into using FigureWidget / FigureWidgetResampler in Google Colab - and circled back to the issue above (for which I created this issue on the Google Colab GitHub repo https://github.com/googlecolab/colabtools/issues/2871)

I don’t think the issue above will get fixed any time soon. It has been open for quite some time (7 months). Thus using FigureWidget / FigureWidgetResampler in Google Colab will keep resulting in problems 😐

Basically I see two options here;

  1. use FigureResampler: you will have all the interactivity (i.e., resampling), but will suffer from a longer loading time. Note that the output will get cleared from the notebook (as the Dash app stops, unless you use inline_persistent).
  2. use FigureWidgetResampler and call .show(): this will return a static figure on which the dynamic resampling cannot be performed (when zooming). However this figure will persist in the cells output.

On another note, are you intending to integrate plotly-resampler in an existing toolkit / code base? If so, @jonasvdd & me will gladly assist / give feedback w.r.t. this πŸ˜ƒ

@jvdd @jonasvdd Thanks a lot for the fast answer. In general I think the functionality provided by the plotly-resampler is great. However, I face issues with getting to work in colab.

Feel free to execute this notebook in colab: https://github.com/ourownstory/neural_prophet/blob/main/tutorials/feature-use/autoregression_yosemite_temps.ipynb

Instructions:

  1. add a cell at the top cointaining:
from google.colab import output
output.enable_custom_widget_manager()
  1. edit cell [4] with to the following:
forecast = m.predict(df)
fig = m.plot(forecast, plotting_backend='plotly')

  1. run the newly added cell as well as cell 1-4

What you will see is that the figure is not displayed. Important note: This happens only when using the custom wrapper function m.plot(). However, wenn plotting a dataframe with the standard .plot() function and plotly backend, then the figure will be displayed. E.g.:

import plotly.graph_objects as go
data = go.Scatter(x =forecast['ds'], y=forecast['y'] )
fig = go.FigureWidget(data=data)
fig

One assumption for the reason of the problem is that there could be a dependencie/ package mismatch. Thanks a lot for having a look at it.