-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
disabled
argument to ui.input_action_button()
and `ui.update_…
…action_button()` Fixes #1465
- Loading branch information
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
shiny/api-examples/input_action_button/app-disabled-core.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from shiny import App, Inputs, reactive, render, ui | ||
|
||
app_ui = ui.page_fluid( | ||
ui.input_text("name", "Your Name"), | ||
ui.input_action_button("greet", "Say Hello", disabled=True), | ||
ui.output_ui("hello"), | ||
) | ||
|
||
|
||
def server(input: Inputs): | ||
@reactive.effect | ||
@reactive.event(input.name) | ||
def set_button_state(): | ||
if input.name(): | ||
ui.update_action_button("greet", disabled=False) | ||
else: | ||
ui.update_action_button("greet", disabled=True) | ||
|
||
@render.ui | ||
@reactive.event(input.greet) | ||
def hello(): | ||
return ui.p(f"Hello, {input.name()}!", class_="fs-1 text-primary mt-3") | ||
|
||
|
||
app = App(app_ui, server) |
20 changes: 20 additions & 0 deletions
20
shiny/api-examples/input_action_button/app-disabled-express.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from shiny import reactive | ||
from shiny.express import input, render, ui | ||
|
||
ui.input_text("name", "Your Name") | ||
ui.input_action_button("greet", "Say Hello", disabled=True) | ||
|
||
|
||
@reactive.effect | ||
@reactive.event(input.name) | ||
def set_button_state(): | ||
if input.name(): | ||
ui.update_action_button("greet", disabled=False) | ||
else: | ||
ui.update_action_button("greet", disabled=True) | ||
|
||
|
||
@render.ui | ||
@reactive.event(input.greet) | ||
def hello(): | ||
return ui.p(f"Hello, {input.name()}!", class_="fs-1 text-primary mt-3") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters