-
Notifications
You must be signed in to change notification settings - Fork 100
Fix input_task_button for modules #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a56dfa
Fix input_task_button for modules
jcheng5 a9248a1
Auto-format code with correct black version
jcheng5 f3ec7c0
Fix CI for Python 3.9
jcheng5 c5cf523
Add unit tests
jcheng5 4936598
Update changelog
jcheng5 7b2f43f
Comment
jcheng5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
import time | ||
|
||
from shiny import App, Inputs, Outputs, Session, module, reactive, render, ui | ||
|
||
|
||
@module.ui | ||
def button_ui(): | ||
return ui.TagList( | ||
ui.input_task_button("btn", label="Go"), | ||
ui.output_text("text_counter"), | ||
) | ||
|
||
|
||
@module.server | ||
def button_server(input: Inputs, output: Outputs, session: Session): | ||
counter = reactive.Value(0) | ||
|
||
@render.text | ||
def text_counter(): | ||
return f"Button clicked {counter()} times" | ||
|
||
@reactive.effect | ||
@reactive.event(input.btn) | ||
def increment_counter(): | ||
time.sleep(0.5) | ||
counter.set(counter() + 1) | ||
|
||
|
||
app_ui = ui.page_fluid(button_ui("mod1")) | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session): | ||
button_server("mod1") | ||
|
||
|
||
app = App(app_ui, server) |
28 changes: 28 additions & 0 deletions
28
tests/playwright/shiny/inputs/input_task_button2/test_input_task_button2.py
This file contains hidden or 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,28 @@ | ||
from __future__ import annotations | ||
|
||
from conftest import ShinyAppProc | ||
from controls import InputTaskButton, OutputText | ||
from playwright.sync_api import Page | ||
|
||
|
||
def click_extended_task_button( | ||
button: InputTaskButton, | ||
) -> None: | ||
button.expect_state("ready") | ||
button.click(timeout=0) | ||
button.expect_state("busy", timeout=0) | ||
button.expect_state("ready", timeout=0) | ||
|
||
|
||
def test_input_action_task_button(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
OutputText(page, "mod1-text_counter").expect_value("Button clicked 0 times") | ||
|
||
# Extended task | ||
button_task = InputTaskButton(page, "mod1-btn") | ||
button_task.expect_label_ready("Go") | ||
button_task.expect_auto_reset(True) | ||
click_extended_task_button(button_task) | ||
|
||
OutputText(page, "mod1-text_counter").expect_value("Button clicked 1 times") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This slight rewrite means we don't need to use pyright pragmas. Same below.