Skip to content

Commit

Permalink
Update dashboard template (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Shotwell committed Jan 25, 2024
1 parent b6907f7 commit 7d4c4d3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 14 deletions.
24 changes: 10 additions & 14 deletions shiny/templates/app-templates/dashboard/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,17 @@ def make_value_box(penguin):
"species", "Filter by species", species, selected=species
),
),
ui.row(
ui.layout_columns(
*[make_value_box(penguin) for penguin in species],
)
ui.layout_columns(
*[make_value_box(penguin) for penguin in species],
),
ui.row(
ui.layout_columns(
ui.card(
ui.card_header("Summary statistics"),
ui.output_data_frame("summary_statistics"),
),
ui.card(
ui.card_header("Penguin bills"),
ui.output_plot("length_depth"),
),
ui.layout_columns(
ui.card(
ui.card_header("Summary statistics"),
ui.output_data_frame("summary_statistics"),
),
ui.card(
ui.card_header("Penguin bills"),
ui.output_plot("length_depth"),
),
),
)
Expand Down
82 changes: 82 additions & 0 deletions shiny/templates/app-templates/dashboard/app-express.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from pathlib import Path

import pandas as pd
import seaborn as sns

from shiny import reactive
from shiny.express import input, render, ui

sns.set_theme(style="white")
df = pd.read_csv(Path(__file__).parent / "penguins.csv", na_values="NA")
species = ["Adelie", "Gentoo", "Chinstrap"]

ui.page_opts(fillable=True)


def count_species(df, species):
return df[df["Species"] == species].shape[0]


with ui.sidebar():
ui.input_slider("mass", "Mass", 2000, 6000, 3400)
ui.input_checkbox_group("species", "Filter by species", species, selected=species)


@reactive.Calc
def filtered_df() -> pd.DataFrame:
filt_df = df[df["Species"].isin(input.species())]
filt_df = filt_df.loc[filt_df["Body Mass (g)"] > input.mass()]
return filt_df


with ui.layout_columns():
with ui.value_box(theme="primary"):
"Adelie"

@render.text
def adelie_count():
return count_species(filtered_df(), "Adelie")

with ui.value_box(theme="primary"):
"Gentoo"

@render.text
def gentoo_count():
return count_species(filtered_df(), "Gentoo")

with ui.value_box(theme="primary"):
"Chinstrap"

@render.text
def chinstrap_count():
return count_species(filtered_df(), "Chinstrap")


with ui.layout_columns():
with ui.card():
ui.card_header("Summary statistics")

@render.data_frame
def summary_statistics():
display_df = filtered_df()[
[
"Species",
"Island",
"Bill Length (mm)",
"Bill Depth (mm)",
"Body Mass (g)",
]
]
return render.DataGrid(display_df, filters=True)

with ui.card():
ui.card_header("Penguin bills")

@render.plot
def length_depth():
return sns.scatterplot(
data=filtered_df(),
x="Bill Length (mm)",
y="Bill Depth (mm)",
hue="Species",
)

0 comments on commit 7d4c4d3

Please sign in to comment.