Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamlit comp updates #42

Merged
merged 8 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

/_inv/
/objects.json

.venv/
__pycache__/
36 changes: 36 additions & 0 deletions docs/apps/comp-streamlit/penguins/classic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path

import pandas as pd
from plots import dist_plot, scatter_plot
from shiny import App, reactive, render, ui

app_ui = ui.page_sidebar(
ui.sidebar(
ui.input_slider("mass", "Mass", 2000, 8000, 6000),
ui.input_checkbox("smoother", "Add Smoother"),
),
ui.card(ui.output_plot(id="scatter")),
ui.card(ui.output_plot(id="mass_distribution")),
)


def server(input, output, session):
infile = Path(__file__).parent / "penguins.csv"
gshotwell marked this conversation as resolved.
Show resolved Hide resolved
df = pd.read_csv(infile)

@reactive.Calc
def filtered_data():
filt_df = df.copy()
filt_df = filt_df.loc[df["Body Mass (g)"] < input.mass()]
return filt_df

@render.plot
def mass_distribution():
return dist_plot(filtered_data())

@render.plot
def scatter():
return scatter_plot(filtered_data(), input.smoother())


app = App(app_ui, server)
34 changes: 34 additions & 0 deletions docs/apps/comp-streamlit/penguins/express.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pathlib import Path

import pandas as pd
from plots import dist_plot, scatter_plot
from shiny import reactive, render, ui
from shiny.express import input, layout

infile = Path(__file__).parent / "penguins.csv"
df = pd.read_csv(infile)

with layout.sidebar():
ui.input_slider("mass", "Mass", 2000, 8000, 6000)
ui.input_checkbox("smoother", "Add Smoother")


@reactive.Calc
def filtered_data():
filt_df = df.copy()
filt_df = filt_df.loc[df["Body Mass (g)"] < input.mass()]
return filt_df


with layout.card():

@render.plot
def scatter():
return scatter_plot(filtered_data(), input.smoother())


with layout.card():

@render.plot
def mass_distribution():
return dist_plot(filtered_data())
Loading