panel: Lets-Plot library plots are not rendering
I’m quite new to Panel and I would really like to start using it since it supports a wide range of Python plotting libraries and is excellent for dashboarding even for professional settings.
However, I happen to be predominantly using the Lets-Plot Python visualization library, which unfortunately, doesn’t seem to be supported by Panel!
When I bind a panel widget to a plotting function that returns a lets-plot plot object, the plot is not rendered (laid out) upon using a Panel layout such as Column.
Here’s a MRE:
from lets_plot import *
import panel as pn
import pandas as pd
LetsPlot.setup_html()
pn.extension()
df = pd.DataFrame({
'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'y': [2, 4, 1, 8, 5, 7, 6, 3, 9, 10],
})
def create_lets_plot(rng):
p = (ggplot(df[:rng]) + geom_line(aes(x='x', y='y')))
return p
slider = pn.widgets.IntSlider(name="range", value=5, start=0, end=len(df))
bound_plot = pn.bind(create_lets_plot, slider)
pn.Column(slider, bound_plot)
The only way to actually visualize anything is by forcing a plot via p.show(), but that will stack the plots multiple times which is obviously undesirable.
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 1
- Comments: 16 (8 by maintainers)
@alshan Massive! 🚀
Works like a charm, just add:
self._plot_spec_as_dict = standardize_dict(spec)in our previousLetsPlotPane()classHi guys, try to “standardize” plot specs before passing it to
buildPlotFromRawSpecs():Its a good starting point. But Maybe we need to consider other things. Like performance.
But the main blocker is for @philippjfr to provide feedback on whether a PR would be appreciated or whether this should live in a seperate package.
@alshan Ah, you’re right! Works perfectly now, thanks!
Would Panel be interested in add a
LetsPlotPane natively @philippjfr ? Or should it be a separate extension?Hey @MarcSkovMadsen,
Thanks for the hint, after messing around with the exports a bit, a temporary solution that seems to work is by passing the
lets-plotplot object into theexport_svg()function and then returning it fromcreate_lets_plot():However, the generated plot(s) are static (no tooltips), and I was unsuccessful in returning the plots in an HTML format (just displays blank upon serving the app).
Appreciate if we can support the plots in an interactive/dynamic way!
Hey guys,
Sorry to revive this randomly but, isn’t the
lets-plotpane class that @MarcSkovMadsen has written (with a minor tweak) is almost complete:I believe it just requires supporting
SupPlotsSpecclass as well (gggridlayer)Hi @OSuwaidi .
buildPlotFromProcessedSpecs()doesn’t apply statistical transformation you needed. Try usingbuildPlotFromRawSpecs()instead.Any updates on this @philippjfr ?
Hi @OSuwaidi
You can try using the below. If you experience issues please report back with minimum, reproducible examples
https://github.com/holoviz/panel/assets/42288570/3e7243cb-e618-46de-825f-af2916a04818
Notes before taking this to next level
widthandheightin theLetsPlot.buildPlotFromProcessedSpecs.view.height,view.widthare null and cannot be used to set the height and width.after_layoutis rerun when ever the window size changesafter_layoutis rerun in infinity if I don’t use thestate.heighthack..innerHTML="".LetsPlotPanecould take a bound function returning aPlotSpecinstead of aPlotSpec. See https://github.com/holoviz/panel/issues/5476precedence=-1on theobjectparameter I will get a serialization error. We should document in theReactiveHTMLdocs how to best solve this issue.Hi @OSuwaidi
The plot probably need an export to SVG or HTML to be displayed in Panel.
I’ll take a look when I get back to my computer. My starting point would be see how it exports it self in https://github.com/JetBrains/lets-plot/blob/master/python-package/lets_plot/export/ggsave_.py
Maybe we should add a lets-plot pane to automatically do this for you and other users?