Action Link

#| 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_link("action_link", "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_link)
    def _():
        count.set(count() + 1)

    @render.text()
    def counter():
        return f"{count()}"

app = App(app_ui, server)
from shiny import reactive
from shiny.express import input, render, ui

ui.input_action_link("action_link", "Increase Number")  

count = reactive.value(0)

@reactive.effect
@reactive.event(input.action_link)
def _():
    count.set(count() + 1)

@render.text()
def counter():
    return f"{count()}"
from shiny import App, reactive, render, ui

app_ui = ui.page_fluid(
    ui.input_action_link("action_link", "Increase Number"),  
    ui.output_text("counter"),
)

def server(input, output, session):
    count = reactive.value(0)

    @reactive.effect
    @reactive.event(input.action_link)  
    def _():
        count.set(count() + 1)

    @render.text()
    def counter():
        return f"{count()}"

app = App(app_ui, server)
No matching items

Relevant Functions

No matching items

Details

An action link appears as a link in your app and has a value that increments each time the user presses the link.

Follow these steps to add an action link to your app:

  1. Add ui.input_action_link() to the UI of your app to create an action link. Where you call this function will determine where the link appears within the app’s layout.
  2. Specify the id and label parameters of ui.input_action_link() to define the action link’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 link:

  1. Use input.<action_link_id()> (e.g., input.action_link()) to access the value of the action link. The server value of an action link is an integer representing the number of clicks.

See also: Action Button