Reactive events
Exercise 2.3
Exercise
Add an input.action_button
to the app, and use @reactive.event
to prevent the text from printing until the user presses the button.
#| standalone: true
#| components: [viewer]
#| layout: horizontal
#| viewerHeight: 800
from shiny import Inputs, Outputs, Session, App, reactive, render, req, ui
app_ui = ui.page_fluid(
ui.input_text("input_txt", "Enter text"),
ui.input_action_button("send", "Enter"),
ui.output_text_verbatim("output_txt"),
)
def server(input, output, session):
@render.text
@reactive.event(input.send)
def output_txt():
return input.input_txt()
app = App(app_ui, server)
Exercise
Add an input.action_button
to the app, and use @reactive.event
to prevent the text from printing until the user presses the button.
#| standalone: true
#| components: [editor, viewer]
#| layout: horizontal
#| viewerHeight: 800
from shiny import Inputs, Outputs, Session, App, reactive, render, req, ui
app_ui = ui.page_fluid(
ui.input_text("input_txt", "Enter text"),
ui.output_text_verbatim("output_txt"),
)
def server(input, output, session):
@render.text
def output_txt():
return input.input_txt()
app = App(app_ui, server)
Exercise
Add an input.action_button
to the app, and use @reactive.event
to prevent the text from printing until the user presses the button.
#| standalone: true
#| components: [editor, viewer]
#| layout: horizontal
#| viewerHeight: 800
from shiny import Inputs, Outputs, Session, App, reactive, render, req, ui
app_ui = ui.page_fluid(
ui.input_text("input_txt", "Enter text"),
ui.input_action_button("send", "Enter"),
ui.output_text_verbatim("output_txt"),
)
def server(input, output, session):
@render.text
@reactive.event(input.send)
def output_txt():
return input.input_txt()
app = App(app_ui, server)
The source code for this exercise is here.