|
1 | 1 | # This file generated by Quarto; do not edit by hand. |
| 2 | +# shiny_mode: core |
2 | 3 |
|
3 | 4 | from __future__ import annotations |
4 | 5 |
|
5 | 6 | from pathlib import Path |
6 | 7 | from shiny import App, Inputs, Outputs, Session, ui |
7 | 8 |
|
| 9 | +import seaborn as sns |
| 10 | +penguins = sns.load_dataset("penguins") |
| 11 | +species = list(penguins["species"].value_counts().index) |
| 12 | +islands = list(penguins["island"].value_counts().index) |
| 13 | + |
| 14 | +# ======================================================================== |
| 15 | + |
8 | 16 |
|
9 | 17 |
|
10 | 18 |
|
11 | 19 | def server(input: Inputs, output: Outputs, session: Session) -> None: |
12 | | - from shiny import ui, render |
13 | | - import seaborn as sns |
14 | | - penguins = sns.load_dataset("penguins") |
| 20 | + from shiny import reactive |
| 21 | + from shiny.express import render, ui |
| 22 | + ui.input_checkbox_group( |
| 23 | + "species", "Species:", |
| 24 | + species, selected = species |
| 25 | + ) |
| 26 | + |
| 27 | + # ======================================================================== |
| 28 | + |
| 29 | + ui.input_checkbox_group( |
| 30 | + "islands", "Islands:", |
| 31 | + islands, selected = islands |
| 32 | + ) |
15 | 33 |
|
16 | 34 | # ======================================================================== |
17 | 35 |
|
18 | | - ui.input_select("x", "Variable:", |
19 | | - choices=["bill_length_mm", "bill_depth_mm"]) |
20 | | - ui.input_select("dist", "Distribution:", choices=["hist", "kde"]) |
| 36 | + ui.input_select("dist", "Distribution:", choices=["kde", "hist"]) |
21 | 37 | ui.input_checkbox("rug", "Show rug marks", value = False) |
22 | 38 |
|
23 | 39 | # ======================================================================== |
24 | 40 |
|
| 41 | + @reactive.calc |
| 42 | + def filtered_penguins(): |
| 43 | + data = penguins[penguins["species"].isin(input.species())] |
| 44 | + data = data[data["island"].isin(input.islands())] |
| 45 | + return data |
| 46 | + |
| 47 | + # ======================================================================== |
| 48 | + |
25 | 49 | @render.plot |
26 | | - def displot(): |
27 | | - sns.displot( |
28 | | - data=penguins, hue="species", multiple="stack", |
29 | | - x=input.x(), rug=input.rug(), kind=input.dist()) |
| 50 | + def depth(): |
| 51 | + return sns.displot( |
| 52 | + filtered_penguins(), x = "bill_depth_mm", |
| 53 | + hue = "species", kind = input.dist(), |
| 54 | + fill = True, rug=input.rug() |
| 55 | + ) |
30 | 56 |
|
31 | 57 | # ======================================================================== |
32 | 58 |
|
33 | 59 |
|
34 | 60 |
|
| 61 | + return None |
| 62 | + |
35 | 63 |
|
36 | | -_static_assets = ["toolbar_files"] |
| 64 | +_static_assets = ["column-layout_files"] |
37 | 65 | _static_assets = {"/" + sa: Path(__file__).parent / sa for sa in _static_assets} |
38 | 66 |
|
39 | 67 | app = App( |
40 | | - Path(__file__).parent / "toolbar.html", |
| 68 | + Path(__file__).parent / "column-layout.html", |
41 | 69 | server, |
42 | 70 | static_assets=_static_assets, |
43 | 71 | ) |
0 commit comments