Skip to content

Commit 4c6d6fd

Browse files
committed
Add code sample for input, links to shiny component browser
1 parent b891381 commit 4c6d6fd

File tree

1 file changed

+15
-10
lines changed
  • docs/dashboards/interactivity/shiny-python

1 file changed

+15
-10
lines changed

docs/dashboards/interactivity/shiny-python/index.qmd

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ Make sure each input ID in your Shiny dashboard is unique. If you use the same I
4444

4545
The second argument for each input function is usually a human-readable string that will be displayed next to the input control. For example, the `ui.input_select()` function passes `"Variable:"`as the second argument, which is why the select box has the label "Variable:" next to it.
4646

47-
<!--
48-
TODO: Introduce components gallery
49-
-->
47+
```` {.python .pymd}
48+
```{{python}}
49+
ui.input_select("x", label="Variable:",
50+
choices=["bill_length_mm", "bill_depth_mm"])
51+
```
52+
````
53+
54+
This example only uses two types of inputs, but Shiny has many more. See the [Shiny Component Browser](https://jcheng.shinyapps.io/shiny-component-browser/) for previews and code snippets.
5055

5156
In many dashboards, it's desirable to visually gather all of your input controls into a sidebar. You can do this by adding the `.sidebar` class to a level 2 header, as in the `## {.sidebar}` line above.
5257

@@ -72,17 +77,15 @@ The `input.x()` and `input.rug()` method calls are retrieving the values of the
7277

7378
Note that our code never calls the `displot()` function! Just the act of defining the function, and decorating it with `@render.plot`, is enough to tell Shiny and Quarto to:
7479

75-
1. Insert a plot into the dashboard at this location.
76-
2. Use the function body to create the plot.
77-
3. Automatically re-run the function body whenever the values of `input.x()`, `input.rug()`, or `input.dist()` change due to user interaction, and use the result to update the existing plot.
78-
79-
This example only contains a single `@render.plot` output, but it's possible for Shiny apps to contain multiple outputs, and outputs of different types, as you'll see in the following example.
80+
* Insert a plot into the dashboard at this location.
81+
* Use the function body to create the plot.
82+
* Automatically re-run the function body whenever the values of `input.x()`, `input.rug()`, or `input.dist()` change due to user interaction, and use the result to update the existing plot.
8083

81-
<!-- TODO: Link to output gallery -->
84+
This example only contains a single `@render.plot` output, but it's possible for Shiny apps to contain multiple outputs, and outputs of different types, as you'll see in the following example. See the [Shiny Component Browser](https://jcheng.shinyapps.io/shiny-component-browser/#outputs) to see what's available.
8285

8386
### Reactive Programming
8487

85-
In the previous section, we said that the `displot` function would re-run whenever any of the inputs it referred to changed. Shiny is a **reactive programming** framework, meaning it automatically tracks the relationships between inputs and outputs in your app. When an input changes, only outputs that are affected by that input are re-rendered. This is a powerful feature that makes it easy to create dashboards that respond to user input efficiently.
88+
In the previous section, we said that the `displot` function would re-run _automatically_ whenever any of the inputs it referred to changed. Shiny is a **reactive programming** framework, meaning it takes care of tracking the relationships between inputs and outputs in your app. When an input changes, only outputs that are affected by that input are re-rendered. This is a powerful feature that makes it easy to create dashboards that respond to user input efficiently.
8689

8790
::: {.callout-note}
8891
The `input` object is designed to be tracked by Shiny's reactive framework,
@@ -176,4 +179,6 @@ To learn more about Shiny for Python interactive documents see the following art
176179

177180
- [Execution Contexts](execution.qmd) goes in depth on when different code cells run (e.g. rendering vs. serving).
178181

182+
- [Shiny Component Browser](https://jcheng.shinyapps.io/shiny-component-browser/) gives a preview of Shiny's built-in input and output widgets.
183+
179184
- [Shiny for Python](https://shiny.posit.co/py/) provides in-depth documentation on all of the available UI and ouput widgets, as well as conceptual discussions on how things work.

0 commit comments

Comments
 (0)