EasySci commited on
Commit
00bb9ed
·
1 Parent(s): 0d76d06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -12
app.py CHANGED
@@ -1,19 +1,47 @@
1
  import panel as pn
 
2
 
3
- pn.extension()
 
4
 
5
- x = pn.widgets.Select(name='x', options=cols)
6
- y = pn.widgets.Select(name='y', options=cols, value='bill_depth_mm')
7
- n_clusters = pn.widgets.IntSlider(name='n_clusters', start=2, end=5, value=3)
8
 
9
- explanation = pn.pane.Markdown(...)
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- def plot(x, y, n_clusters):
12
- ...
 
 
 
 
 
 
 
 
 
 
13
 
14
- interactive_plot = pn.bind(plot, x, y, n_clusters)
 
15
 
16
- pn.Row(
17
- pn.WidgetBox(x, y, n_clusters, explanation),
18
- interactive_plot
19
- )
 
 
 
 
 
 
1
  import panel as pn
2
+ import hvplot.pandas
3
 
4
+ # Load Data
5
+ from bokeh.sampledata.autompg import autompg_clean as df
6
 
7
+ # Make DataFrame Pipeline Interactive
8
+ idf = df.interactive()
 
9
 
10
+ # Define Panel widgets
11
+ cylinders = pn.widgets.IntSlider(name='Cylinders', start=4, end=8, step=2)
12
+ mfr = pn.widgets.ToggleGroup(
13
+ name='MFR',
14
+ options=['ford', 'chevrolet', 'honda', 'toyota', 'audi'],
15
+ value=['ford', 'chevrolet', 'honda', 'toyota', 'audi'],
16
+ button_type='success')
17
+ yaxis = pn.widgets.RadioButtonGroup(
18
+ name='Y axis',
19
+ options=['hp', 'weight'],
20
+ button_type='success'
21
+ )
22
 
23
+ # Combine pipeline and widgets
24
+ ipipeline = (
25
+ idf[
26
+ (idf.cyl == cylinders) &
27
+ (idf.mfr.isin(mfr))
28
+ ]
29
+ .groupby(['origin', 'mpg'])[yaxis].mean()
30
+ .to_frame()
31
+ .reset_index()
32
+ .sort_values(by='mpg')
33
+ .reset_index(drop=True)
34
+ )
35
 
36
+ # Pipe to hvplot
37
+ ihvplot = ipipeline.hvplot(x='mpg', y=yaxis, by='origin', color=["#ff6f69", "#ffcc5c", "#88d8b0"], line_width=6, height=400)
38
 
39
+ # Layout using Template
40
+ template = pn.template.FastListTemplate(
41
+ title='Interactive DataFrame Dashboards with hvplot .interactive',
42
+ sidebar=[cylinders, 'Manufacturers', mfr, 'Y axis' , yaxis],
43
+ main=[ihvplot.panel()],
44
+ accent_base_color="#88d8b0",
45
+ header_background="#88d8b0",
46
+ )
47
+ template.servable()