shiny.ui.input_action_button#

shiny.ui.input_action_button(id, label, *, icon=None, width=None, **kwargs)#

Creates an action button whose value is initially zero, and increments by one each time it is pressed.

Parameters
  • id (str) – An input id.

  • label (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – An input label.

  • icon (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – An icon to appear inline with the button/link.

  • width (Optional[str]) – The CSS width, e.g. ‘400px’, or ‘100%’

  • kwargs (Union[str, float, bool, None]) – Attributes to be applied to the button.

Return type

A UI element

Notes

Server value

An integer representing the number of clicks.

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *
import numpy as np
import matplotlib.pyplot as plt

app_ui = ui.page_fluid(
    ui.input_slider("n", "Number of observations", min=0, max=1000, value=500),
    ui.input_action_button("go", "Go!", class_="btn-success"),
    ui.output_plot("plot"),
)

def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.plot(alt="A histogram")
    # Use reactive.event() to invalidate the plot only when the button is pressed
    # (not when the slider is changed)
    @reactive.event(lambda: input.go, ignore_none=False)
    def plot():
        np.random.seed(19680801)
        x = 100 + 15 * np.random.randn(input.n())
        fig, ax = plt.subplots()
        ax.hist(x, bins=30, density=True)
        return fig


app = App(app_ui, server)