0

I am using hvplot + panel. When using hvplot, each plot comes with its related widgets by default. However, for my situation, multiple hvplot share the same widgets and can be combined into sidebar (once configured, it can be hiden).

However, although I am able to add the widget to the sidebar, I have not been able to hide the widget that comes with the hvplot by default.

Context:

import pandas as pd
import numpy as np
import panel as pn
pn.extension('tabulator')
import hvplot.pandas
import holoviews as hv

df = pd.read_csv('https://raw.githubusercontent.com/owid/co2-data/master/owid-co2-data.csv')
df = df.fillna(0)
df['gdp_per_capita'] = np.where(df['population']!= 0, df['gdp']/ df['population'], 0)

idf = df.interactive()

year_slider = pn.widgets.IntSlider(name='Year slider', start=1750, end=2020, step=5, value=1850)


yaxis_co2 = pn.widgets.RadioButtonGroup(
    name='Y axis', 
    options=['co2', 'co2_per_capita'],
    button_type='success'
)
continents = ['World', 'Asia', 'Oceania', 'Europe', 'Africa', 'North America', 'South America', 'Antarctica']

co2_pipeline = (
    idf[
        (idf.year <= year_slider) &
        (idf.country.isin(continents))
    ]
    .groupby(['country', 'year','iso_code'])[yaxis_co2].mean()
    .to_frame()
    .reset_index()
    .sort_values(by='year')  
    .reset_index(drop=True)
)
co2_plot = co2_pipeline.hvplot(x = 'year', by=['iso_code','country'], y=yaxis_co2,line_width=2, title="CO2 emission by continent")


template = pn.template.FastListTemplate(
title='World CO2 emission dashboard', 
sidebar=[pn.pane.Markdown("# CO2 Emissions and Climate Change"), 
                 year_slider],
        main=[pn.Row(pn.Column(yaxis_co2, 
                               co2_plot.panel(width=700), margin=(0,25)), 
                     ), 
              ]
    )
template.servable();
John
  • 348
  • 3
  • 15

0 Answers0