Skip to content

Commit 2dda3e9

Browse files
authored
feat: Add input_submit_textarea() and update_submit_textarea() (#2099)
1 parent c1d5941 commit 2dda3e9

File tree

68 files changed

+867
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+867
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [UNRELEASED]
99

10+
### New features
11+
12+
* Added a new `input_submit_textarea()` input element, which is similar to `input_text_area()`, but includes a submit button to only submit the text changes to the server on click. This is especially useful when the input text change triggers a long-running operation and/or the user wants to type longer-form input and review it before submitting it. (#2099)
13+
1014
### Bug fixes
1115

1216
* Fixed `ui.tooltip()`'s `options` parameter to properly pass Bootstrap tooltip options to the underlying web component. (#2101)

docs/_quartodoc-core.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ quartodoc:
5555
- ui.input_numeric
5656
- ui.input_text
5757
- ui.input_text_area
58+
- ui.input_submit_textarea
5859
- ui.input_password
5960
- ui.input_action_button
6061
- ui.input_action_link
@@ -166,6 +167,7 @@ quartodoc:
166167
- ui.update_text
167168
- name: ui.update_text_area
168169
dynamic: "shiny.ui.update_text"
170+
- ui.update_submit_textarea
169171
- ui.update_navset
170172
- ui.update_action_button
171173
- ui.update_action_link

docs/_quartodoc-express.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ quartodoc:
2727
- express.ui.input_numeric
2828
- express.ui.input_text
2929
- express.ui.input_text_area
30+
- express.ui.input_submit_textarea
3031
- express.ui.input_password
3132
- express.ui.input_action_button
3233
- express.ui.input_action_link
@@ -126,6 +127,7 @@ quartodoc:
126127
- express.ui.update_numeric
127128
- express.ui.update_text
128129
- express.ui.update_text_area
130+
- express.ui.update_submit_textarea
129131
- express.ui.update_navset
130132
- express.ui.update_action_button
131133
- express.ui.update_action_link

docs/_quartodoc-testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ quartodoc:
3939
- playwright.controller.InputSelectize
4040
- playwright.controller.InputSlider
4141
- playwright.controller.InputSliderRange
42+
- playwright.controller.InputSubmitTextarea
4243
- playwright.controller.InputSwitch
4344
- playwright.controller.InputTaskButton
4445
- playwright.controller.InputText

shiny/_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
shiny_html_deps = "1.11.1.9000"
1+
shiny_html_deps = "1.11.1.9001"
22
bslib = "0.9.0.9000"
33
htmltools = "0.5.8.9000"
44
bootstrap = "5.3.1"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
3+
from shiny import App, Inputs, Outputs, Session, render, ui
4+
5+
app_ui = ui.page_fluid(
6+
ui.input_submit_textarea("text", placeholder="Enter some input..."),
7+
ui.output_text("value"),
8+
)
9+
10+
11+
def server(input: Inputs, output: Outputs, session: Session):
12+
@render.text
13+
def value():
14+
if "text" in input:
15+
# Simulate processing time
16+
time.sleep(2)
17+
return f"You entered: {input.text()}"
18+
else:
19+
return "Submit some input to see it here."
20+
21+
22+
app = App(app_ui, server)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import time
2+
3+
from shiny.express import input, render, ui
4+
5+
ui.input_submit_textarea("text", placeholder="Enter some input...")
6+
7+
8+
@render.text
9+
def value():
10+
if "text" in input:
11+
# Simulate processing time
12+
time.sleep(2)
13+
return f"You entered: {input.text()}"
14+
else:
15+
return "Submit some input to see it here."
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
2+
3+
app_ui = ui.page_fluid(
4+
ui.input_submit_textarea(
5+
"comment",
6+
label="Your Comment",
7+
placeholder="Type your comment here...",
8+
rows=2,
9+
toolbar=[
10+
ui.input_action_button("clear", "Clear", class_="btn-sm btn-danger"),
11+
ui.input_action_button("template", "Use Template", class_="btn-sm"),
12+
],
13+
),
14+
ui.output_text("submitted_comment"),
15+
)
16+
17+
18+
def server(input: Inputs, output: Outputs, session: Session):
19+
@reactive.effect
20+
@reactive.event(input.clear)
21+
def _():
22+
ui.update_submit_textarea(
23+
"comment",
24+
value="",
25+
placeholder="Type your comment here...",
26+
)
27+
28+
@reactive.effect
29+
@reactive.event(input.template)
30+
def _():
31+
ui.update_submit_textarea(
32+
"comment",
33+
value="Thank you for your feedback. We appreciate your input!",
34+
placeholder="",
35+
label="Your Comment (Template Applied)",
36+
)
37+
38+
@render.text
39+
def submitted_comment():
40+
if "comment" in input:
41+
return f"Submitted: {input.comment()}"
42+
return "No comment submitted yet."
43+
44+
45+
app = App(app_ui, server)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from shiny import reactive, render
2+
from shiny.express import input, ui
3+
4+
ui.input_submit_textarea(
5+
"comment",
6+
label="Your Comment",
7+
placeholder="Type your comment here...",
8+
rows=2,
9+
toolbar=[
10+
ui.input_action_button("clear", "Clear", class_="btn-sm btn-danger"),
11+
ui.input_action_button("template", "Use Template", class_="btn-sm"),
12+
],
13+
)
14+
15+
16+
@reactive.effect
17+
@reactive.event(input.clear)
18+
def _():
19+
ui.update_submit_textarea(
20+
"comment",
21+
value="",
22+
placeholder="Type your comment here...",
23+
)
24+
25+
26+
@reactive.effect
27+
@reactive.event(input.template)
28+
def _():
29+
ui.update_submit_textarea(
30+
"comment",
31+
value="Thank you for your feedback. We appreciate your input!",
32+
placeholder="",
33+
label="Your Comment (Template Applied)",
34+
)
35+
36+
37+
@render.text
38+
def submitted_comment():
39+
if "comment" in input:
40+
return f"Submitted: {input.comment()}"
41+
return "No comment submitted yet."

shiny/express/ui/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
input_select,
6565
input_selectize,
6666
input_slider,
67+
input_submit_textarea,
6768
input_switch,
6869
input_task_button,
6970
input_text,
@@ -102,6 +103,7 @@
102103
update_selectize,
103104
update_sidebar,
104105
update_slider,
106+
update_submit_textarea,
105107
update_switch,
106108
update_task_button,
107109
update_text,
@@ -220,6 +222,7 @@
220222
"input_select",
221223
"input_selectize",
222224
"input_slider",
225+
"input_submit_textarea",
223226
"bind_task_button",
224227
"input_task_button",
225228
"input_text",
@@ -243,6 +246,7 @@
243246
"update_select",
244247
"update_selectize",
245248
"update_slider",
249+
"update_submit_textarea",
246250
"update_task_button",
247251
"update_text",
248252
"update_text_area",

0 commit comments

Comments
 (0)