Skip to content

Instantly share code, notes, and snippets.

@cisaacstern
Created January 26, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cisaacstern/60ea39c273f074bd83e83cd76e96ec82 to your computer and use it in GitHub Desktop.
Save cisaacstern/60ea39c273f074bd83e83cd76e96ec82 to your computer and use it in GitHub Desktop.
An example Panel app which changes histograms based on date input.
import random
import datetime as dt
import pandas as pd
import panel as pn
# generate sample data
start = dt.date(2020, 1, 26)
dates = [start + dt.timedelta(days=i) for i in range(10)]
rand = [random.sample(range(0, 100), 50) for i in range(10)]
df = pd.DataFrame(rand, index=dates)
# define widget
date_picker = pn.widgets.DatePicker(name='Date Picker',
start=dates[0],
end=dates[-1],
value=dates[0]
)
# bins for histogram
bins = [i for i in range(0, 110, 10)]
hist = df.loc[dates[0]].hist(bins=bins)
# create function
@pn.depends(date_picker.param.value)
def hourly_plot(date=date_picker.param.value, bins=bins, hist=hist):
hist.figure.clear()
hist = df.loc[date].hist(bins=bins)
return hist.figure
# define panel
hourly = pn.Row(
pn.Column(date_picker),
hourly_plot
)
hourly.servable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment