CoolFace
Apppublic

sophiamyang/Panel_apps

sourceHugging Faceupdated 4y agoView on Hugging Face
5likes
hvplot_interactive.py53 linesDownload Raw Back to root
1import panel as pn2pn.extension('tabulator', sizing_mode="stretch_width")3 4import hvplot.pandas5 6# Load Data7from bokeh.sampledata.autompg import autompg_clean as df8 9# Make DataFrame Pipeline Interactive10idf = df.interactive()11 12# Define Panel widgets13cylinders = pn.widgets.IntSlider(name='Cylinders', start=4, end=8, step=2)14mfr = pn.widgets.ToggleGroup(15    name='MFR',16    options=['ford', 'chevrolet', 'honda', 'toyota', 'audi'], 17    value=['ford', 'chevrolet', 'honda', 'toyota', 'audi'],18    button_type='success')19yaxis = pn.widgets.RadioButtonGroup(20    name='Y axis', 21    options=['hp', 'weight'],22    button_type='success'23)24 25# Combine pipeline and widgets26ipipeline = (27    idf[28        (idf.cyl == cylinders) & 29        (idf.mfr.isin(mfr))30    ]31    .groupby(['origin', 'mpg'])[yaxis].mean()32    .to_frame()33    .reset_index()34    .sort_values(by='mpg')  35    .reset_index(drop=True)36)37 38# Pipe to hvplot39ihvplot = ipipeline.hvplot(x='mpg', y=yaxis, by='origin', color=["#ff6f69", "#ffcc5c", "#88d8b0"], line_width=6, height=400)40 41# Pipe to table 42itable = ipipeline.pipe(pn.widgets.Tabulator, pagination='remote', page_size=10)43itable44 45# Layout using Template46template = pn.template.FastListTemplate(47    title='Interactive DataFrame Dashboards with hvplot .interactive', 48    sidebar=[cylinders, 'Manufacturers', mfr, 'Y axis' , yaxis],49    main=[ihvplot.panel(), itable.panel()],50    accent_base_color="#88d8b0",51    header_background="#88d8b0",52)53template.servable()