panel-altair-dashboard icon indicating copy to clipboard operation
panel-altair-dashboard copied to clipboard

Dashboard coming blank

Open lavahammer opened this issue 5 years ago • 2 comments

Hey your work was great. But I use this on an excel dataset, it does not work.

set a title for your dashboard

title = '## Sentiment Timeseries'

subtitle = 'This dashboard allows you to see sentiment timeseries'

create list of company names (tickers)

tickers = ['Negative', 'Positive']

this creates the dropdown widget

ticker = pn.widgets.Select(name='Polarity', options=tickers)

this creates the date range slider

date_range_slider = pn.widgets.DateRangeSlider( name='Date Range Slider', start=dt.datetime(2015, 1, 1), end=dt.datetime(2020, 1, 1), value=(dt.datetime(2015, 1, 1), dt.datetime(2020, 1, 1)) )

tell Panel what your plot "depends" on.

This defines what should trigger a change in the chart.

both values in depends() will be used in our below Altair chart as filters

@pn.depends(ticker.param.value, date_range_slider.param.value) def get_plot(ticker, date_range): # start function

# Load and format the data
df = pd.read_excel(r"C:\Users\shubhjha\Downloads\test_viz.xlsx") # define df
#df['timestamp'] = pd.to_datetime(df['timestamp']) # format date as datetime

# create a date filter that uses values from the date range slider
start_date = date_range_slider.value[0] # store the first date range slider value in a var
end_date = date_range_slider.value[1] # store the end date in a var
mask = (df['timestamp'] > start_date) & (df['timestamp'] <= end_date) # create filter mask for the dataframe
df = df.loc[mask] # filter the dataframe

# create the Altair chart object
chart = alt.Chart(df).mark_area(color="#0c1944", opacity=0.8).encode(x='timestamp', y='score', tooltip=alt.Tooltip(['timestamp','score'])).transform_filter((datum.symbol == ticker))
# this ties in the filter from the dropdown selection

return chart

create the Panel object, passing in all smaller objects

dashboard = pn.Row(pn.Column(title, subtitle, ticker, date_range_slider),get_plot )

draw chart function!

lavahammer avatar Aug 28 '19 01:08 lavahammer

Thank you!

Are you getting an error message of any kind? If so, could you include it here so I can try to help?

If no error message, and it's just a blank output cell in Jupyter Notebook, I suspect it's something on the Altair side. This happens when the Vega-Lite renderer is not formatted properly.

You can find details on how to troubleshoot issues in Altair here.

bendoesdata avatar Aug 28 '19 16:08 bendoesdata

Thank you so much for your response.

a) I am not getting any error message. The dashboard is just blank. b) When I try to plot the timeseries using just the below command without any interactive dashboard, it works fine.

alt.Chart(data).mark_line().encode( x='timestamp:T', y='score:Q', color='polarity' ).interactive().serve()

I tried the altair documentation. Doesn't help.

lavahammer avatar Aug 28 '19 16:08 lavahammer