Hvplot .interactive - A truly amazing api for making interactive data exploration and data apps from Pandas DataFrames

Inspired by @philippjfr PyData 2021 Talk Build polished, data-driven applications directly from your Pandas or XArray pipelines I tried out the hvplot .interactive api with Panel.

It is truly amazing! Streamlit made a revolutionary run script top to bottom api. I think this is in the same category. After having learned it, it’s really intuitive, simple and powerful. You should try it out.

Check out my gist hvPlot .interactive with Panel

The core of the code is the pipeline that can be made interactive with widgets and produce the interactive plot and table.

# Widgets
resample = pn.widgets.Select(value="D", options=["D", "W", "M"], name="Sampling Frequency")
window = pn.widgets.IntSlider(value=50, start=10, end=100, name="Rolling Window Length")
center = pn.widgets.Checkbox(value=True, name="Center")
win_type = pn.widgets.Select(value="gaussian", options=[None, "gaussian"], name="Window Type")
std = pn.widgets.IntSlider(value=10, start=5, end=20, name="std")
line_width = pn.widgets.IntSlider(value=6, start=1, end=20, name="Line Width")

# A Pandas Dataframe made .interactive with hvPlot
pipeline = (
    seattle_bikes.interactive()
    .resample(resample)
    .sum()
    .rolling(window, center=center, win_type=win_type)
    .sum(std=std)
    .dropna()
)

# Interactive Plot
plot = pn.panel(
    pipeline.hvplot(
        responsive=True,
        color=PALETTE,
        line_width=line_width,
        yformatter="%.0f",
    ).holoviews().opts(legend_position='top_left'),
    sizing_mode="stretch_both",
    name="Plot",
)

# Interactive Table
table = pipeline.pipe(
    pn.widgets.Tabulator,
    pagination="remote",
    page_size=20,
    theme="fast",
    sizing_mode="stretch_both",
).panel(name="Table")

The full code and additional resources is in my gist https://gist.github.com/MarcSkovMadsen/ffb273636dced88705c8c88d5ee28f23

3 Likes

FYI. @Hoxbro , @xavArtley , @Material-Scientist , @nghenzi2019

This is great - I didn’t know you could do it like that! :exploding_head:

2 Likes

It’s also amazing in the notebook. Check out this gist HvplotInteractive.ipynb

I believe @philippjfr has invented something as simple and intuitive as the Streamlit api but without the slowness of rerunning the entire script and the overhead to remember to add caching.

And it works both in the notebook and your python file.

1 Like