Action Button
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
## file: app.py
from shiny import App, reactive, render, ui
app_ui = ui.page_fluid(
ui.row(
ui.column(6, ui.input_action_button("action_button", "Increase Number")),
ui.column(6, ui.output_text("counter").add_class("display-5 mb-0")),
{"class": "vh-100 justify-content-center align-items-center px-5"},
).add_class("text-center")
)
def server(input, output, session):
count = reactive.value(0)
@reactive.effect
@reactive.event(input.action_button)
def _():
count.set(count() + 1)
@render.text
def counter():
return f"{count()}"
app = App(app_ui, server)
from shiny import App, reactive, render, ui
app_ui = ui.page_fluid(
ui.input_action_button("action_button", "Action"),
ui.output_text("counter"),
)
def server(input, output, session):
@render.text()
@reactive.event(input.action_button)
def counter():
return f"{input.action_button()}"
app = App(app_ui, server)
Relevant Functions
-
ui.input_action_button
ui.input_action_button(id, label, *, icon=None, width=None, **kwargs)
-
reactive.event
reactive.event(*args, ignore_none=True, ignore_init=False)
Details
An action button appears as a button and has a value that increments each time the user presses the button.
Follow these steps to add an action button to your app:
Add
ui.input_action_button()
to the UI of your app to create an action button. Where you call this function will determine where the button will appear within the app’s layout.Specify the
id
andlabel
parameters ofui.input_action_button()
to define the button’s identifier and label.
The value of an input component is accessible as a reactive value within the server()
function. To access the value of an action button:
- Use
input.<action_button_id()>
(e.g.,input.action_button()
) to access the value of the action button. The server value of an action button is an integer representing the number of clicks.
See also: Action Link