| |
| import panel as pn |
| import pandas as pd |
| import altair as alt |
| from vega_datasets import data |
|
|
| |
| pn.extension(design='bootstrap') |
|
|
| |
| pn.extension('vega') |
|
|
| |
| template = pn.template.BootstrapTemplate( |
| title='SI649 Walkthrough', |
| ) |
|
|
| |
| maincol = pn.Column() |
|
|
| |
| maincol.append("# Markdown Title") |
| maincol.append("I can format in cool ways. Like **bold** or *italics* or ***both*** or ~~strikethrough~~ or `code` or [links](https://panel.holoviz.org)") |
| maincol.append("I am writing a link [to the streamlit documentation page](https://docs.streamlit.io/en/stable/api.html)") |
| maincol.append('') |
|
|
| |
| cars_url = "https://raw.githubusercontent.com/altair-viz/vega_datasets/master/vega_datasets/_data/cars.json" |
| cars = pd.read_json(cars_url) |
| temps = data.seattle_weather() |
|
|
| maincol.append(temps.head(10)) |
|
|
| |
| hp_mpg = alt.Chart(cars).mark_circle(size=80).encode( |
| x='Horsepower:Q', |
| y='Miles_per_Gallon:Q', |
| color='Origin:N' |
| ) |
|
|
| |
| |
|
|
| |
| simpleslider = pn.widgets.IntSlider(name='Simple Slider', start=0, end=100, value=0) |
|
|
| |
| def square(x): |
| return f'{x} squared is {x**2}' |
|
|
|
|
| |
| row = pn.Column(pn.bind(square,simpleslider)) |
|
|
| |
| maincol.append(simpleslider) |
| maincol.append(row) |
|
|
| |
| flip = False |
|
|
| |
| def makeChartVisible(val): |
| global flip |
| if (flip == True): |
| flip = not flip |
| return pn.pane.Vega(hp_mpg) |
| else: |
| flip = not flip |
| return pn.panel("Click the button to see the chart") |
| |
| |
| btn = pn.widgets.Button(name='Click me') |
| row = pn.Row(pn.bind(makeChartVisible, btn)) |
|
|
| |
| maincol.append(btn) |
| maincol.append(row) |
|
|
| |
| basechart = alt.Chart(cars).mark_circle(size=80,opacity=0.5).encode( |
| x='Horsepower:Q', |
| y='Acceleration:Q', |
| color="Origin:N" |
| ) |
|
|
| |
| currentoption = pn.panel(basechart) |
|
|
| |
| select = pn.widgets.Select(name='Select', options=['Horsepower','Acceleration','Miles_per_Gallon']) |
|
|
| |
| |
| def changeOption(val): |
| |
| chrt = currentoption.object |
| |
| chrt = chrt.encode( |
| y=val+":Q" |
| ) |
| |
| currentoption.object = chrt |
|
|
| |
| maincol.append(select) |
| |
| chartchange = pn.Row(pn.bind(changeOption, select)) |
| |
| maincol.append(chartchange) |
| maincol.append(currentoption) |
|
|
| |
| template.main.append(maincol) |
|
|
| |
| template.servable(title="SI649 Walkthrough") |