Skip to content

Commit 9f0e753

Browse files
Gordon Shotwelljcheng5schloerke
authored
feat: Pass options to input_selectize (#745)
Co-authored-by: Joe Cheng <[email protected]> Co-authored-by: Barret Schloerke <[email protected]>
1 parent 4b737f4 commit 9f0e753

File tree

11 files changed

+327
-164
lines changed

11 files changed

+327
-164
lines changed

CHANGELOG.md

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

2727
* Added `App.on_shutdown` method for registering a callback to be called when the app is shutting down. (#907)
2828

29+
* You can now pass options to `ui.input_selectize` see the [selectize.js](https://selectize.dev/docs/API/selectize) docs for available options. (#914, #158)
30+
31+
* `ui.input_selectize` gains the `remove_button` argument which allows you to control the visibility of the remove button.
32+
2933
### Bug fixes
3034

3135
* CLI command `shiny create`... (#965)

shiny/api-examples/Calc/app.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

shiny/api-examples/Effect/app.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

shiny/api-examples/input_selectize/app.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1+
from html import escape # noqa: F401
2+
13
from shiny import App, Inputs, Outputs, Session, render, ui
24

5+
states = {
6+
"East Coast": {"NY": "New York", "NJ": "New Jersey", "CT": "Connecticut"},
7+
"West Coast": {"WA": "Washington", "OR": "Oregon", "CA": "California"},
8+
"Midwest": {"MN": "Minnesota", "WI": "Wisconsin", "IA": "Iowa"},
9+
}
10+
311
app_ui = ui.page_fluid(
412
ui.input_selectize(
513
"state",
614
"Choose a state:",
7-
{
8-
"East Coast": {"NY": "New York", "NJ": "New Jersey", "CT": "Connecticut"},
9-
"West Coast": {"WA": "Washington", "OR": "Oregon", "CA": "California"},
10-
"Midwest": {"MN": "Minnesota", "WI": "Wisconsin", "IA": "Iowa"},
11-
},
15+
states,
1216
multiple=True,
1317
),
1418
ui.output_text("value"),
19+
ui.input_selectize(
20+
"state",
21+
"Selectize Options",
22+
states,
23+
multiple=True,
24+
options=(
25+
{
26+
"placeholder": "Enter text",
27+
"render": ui.js_eval(
28+
'{option: function(item, escape) {return "<div><strong>Select " + escape(item.label) + "</strong></div>";}}'
29+
),
30+
"create": True,
31+
}
32+
),
33+
),
34+
ui.input_selectize(
35+
"state",
36+
"Selectize plugins",
37+
states,
38+
multiple=True,
39+
options={"plugins": ["clear_button"]},
40+
),
1541
)
1642

1743

shiny/express/ui/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
nav_spacer,
9999
Progress,
100100
value_box_theme,
101+
js_eval,
101102
)
102103

103104
from ._cm_components import (
@@ -269,6 +270,7 @@
269270
"page_opts",
270271
# Imports from ._hold
271272
"hold",
273+
"js_eval",
272274
)
273275

274276

shiny/ui/__init__.py

Lines changed: 89 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,36 @@
33
layout helpers, page-level containers, and more.
44
"""
55

6-
from ._bootstrap import (
7-
row,
8-
column,
9-
panel_well,
10-
panel_conditional,
11-
panel_title,
12-
panel_fixed,
13-
panel_absolute,
14-
help_text,
15-
)
16-
from ._sidebar import (
17-
Sidebar,
18-
sidebar,
19-
layout_sidebar,
20-
update_sidebar,
21-
panel_sidebar,
22-
panel_main,
6+
from htmltools import (
7+
HTML,
8+
Tag,
9+
TagAttrs,
10+
TagAttrValue,
11+
TagChild,
12+
TagList,
13+
a,
14+
br,
15+
code,
16+
div,
17+
em,
18+
h1,
19+
h2,
20+
h3,
21+
h4,
22+
h5,
23+
h6,
24+
head_content,
25+
hr,
26+
img,
27+
p,
28+
pre,
29+
span,
30+
strong,
31+
tags,
2332
)
2433

25-
from ._layout import layout_column_wrap
26-
from ._layout_columns import layout_columns
27-
28-
2934
# Expose the following modules for extended usage: ex: ui.fill.as_fill_item(x)
30-
from . import css # noqa: F401 # pyright: ignore[reportUnusedImport]
31-
from . import fill # noqa: F401 # pyright: ignore[reportUnusedImport]
32-
33-
from ._card import (
34-
card,
35-
CardItem,
36-
card_header,
37-
card_footer,
38-
)
39-
35+
from . import css, fill # noqa: F401 # pyright: ignore[reportUnusedImport]
4036
from ._accordion import (
4137
AccordionPanel,
4238
accordion,
@@ -46,132 +42,126 @@
4642
update_accordion,
4743
update_accordion_panel,
4844
)
49-
45+
from ._bootstrap import (
46+
column,
47+
help_text,
48+
panel_absolute,
49+
panel_conditional,
50+
panel_fixed,
51+
panel_title,
52+
panel_well,
53+
row,
54+
)
55+
from ._card import (
56+
CardItem,
57+
card,
58+
card_footer,
59+
card_header,
60+
)
5061
from ._download_button import download_button, download_link
51-
from ._plot_output_opts import brush_opts, click_opts, dblclick_opts, hover_opts
5262
from ._include_helpers import include_css, include_js
5363
from ._input_action_button import input_action_button, input_action_link
5464
from ._input_check_radio import (
5565
input_checkbox,
5666
input_checkbox_group,
57-
input_switch,
5867
input_radio_buttons,
68+
input_switch,
5969
)
6070
from ._input_date import input_date, input_date_range
6171
from ._input_file import input_file
6272
from ._input_numeric import input_numeric
6373
from ._input_password import input_password
6474
from ._input_select import input_select, input_selectize
65-
from ._input_slider import input_slider, SliderValueArg, SliderStepArg, AnimationOptions
75+
from ._input_slider import AnimationOptions, SliderStepArg, SliderValueArg, input_slider
6676
from ._input_task_button import bind_task_button, input_task_button
6777
from ._input_text import input_text, input_text_area
6878
from ._input_update import (
6979
update_action_button,
7080
update_action_link,
7181
update_checkbox,
72-
update_switch,
7382
update_checkbox_group,
74-
update_radio_buttons,
7583
update_date,
7684
update_date_range,
85+
update_navs,
7786
update_numeric,
87+
update_popover,
88+
update_radio_buttons,
7889
update_select,
7990
update_selectize,
8091
update_slider,
92+
update_switch,
8193
update_task_button,
8294
update_text,
8395
update_text_area,
84-
update_navs,
8596
update_tooltip,
86-
update_popover,
8797
)
8898
from ._insert import insert_ui, remove_ui
99+
from ._layout import layout_column_wrap
100+
from ._layout_columns import layout_columns
89101
from ._markdown import markdown
90-
from ._modal import modal_button, modal, modal_show, modal_remove
102+
from ._modal import modal, modal_button, modal_remove, modal_show
91103
from ._navs import (
92-
nav_panel,
93-
nav_menu,
104+
nav,
94105
nav_control,
106+
nav_menu,
107+
nav_panel,
95108
nav_spacer,
96-
navset_tab,
97-
navset_pill,
98-
navset_underline,
109+
navset_bar,
99110
navset_card_pill,
100-
navset_card_underline,
101111
navset_card_tab,
102-
navset_pill_list,
112+
navset_card_underline,
103113
navset_hidden,
104-
navset_bar,
114+
navset_pill,
105115
# Deprecated
106116
navset_pill_card,
117+
navset_pill_list,
118+
navset_tab,
107119
navset_tab_card,
108-
nav,
120+
navset_underline,
109121
)
110-
from ._notification import notification_show, notification_remove
122+
from ._notification import notification_remove, notification_show
111123
from ._output import (
112-
output_plot,
124+
output_code,
113125
output_image,
126+
output_plot,
127+
output_table,
114128
output_text,
115-
output_code,
116129
output_text_verbatim,
117-
output_table,
118130
output_ui,
119131
)
120132
from ._page import (
121-
page_sidebar,
122-
page_navbar,
133+
page_auto,
134+
page_bootstrap,
123135
page_fillable,
124-
page_fluid,
125136
page_fixed,
126-
page_bootstrap,
127-
page_auto,
137+
page_fluid,
138+
page_navbar,
128139
page_output,
140+
page_sidebar,
129141
)
130-
from ._progress import Progress
131-
132-
from .dataframe import output_data_frame
133-
142+
from ._plot_output_opts import brush_opts, click_opts, dblclick_opts, hover_opts
134143
from ._popover import popover
144+
from ._progress import Progress
145+
from ._sidebar import (
146+
Sidebar,
147+
layout_sidebar,
148+
panel_main,
149+
panel_sidebar,
150+
sidebar,
151+
update_sidebar,
152+
)
153+
from ._tooltip import tooltip
154+
from ._utils import js_eval
135155
from ._valuebox import (
136-
value_box,
137-
value_box_theme,
156+
ShowcaseLayout,
157+
ValueBoxTheme,
138158
showcase_bottom,
139159
showcase_left_center,
140160
showcase_top_right,
141-
ValueBoxTheme,
142-
ShowcaseLayout,
143-
)
144-
from ._tooltip import tooltip
145-
146-
147-
from htmltools import (
148-
TagList,
149-
Tag,
150-
TagChild,
151-
TagAttrs,
152-
TagAttrValue,
153-
tags,
154-
HTML,
155-
head_content,
156-
p,
157-
h1,
158-
h2,
159-
h3,
160-
h4,
161-
h5,
162-
h6,
163-
a,
164-
br,
165-
div,
166-
span,
167-
pre,
168-
code,
169-
img,
170-
strong,
171-
em,
172-
hr,
161+
value_box,
162+
value_box_theme,
173163
)
174-
164+
from .dataframe import output_data_frame
175165

176166
__all__ = (
177167
# _bootstrap
@@ -356,4 +346,6 @@
356346
"strong",
357347
"em",
358348
"hr",
349+
# utils
350+
"js_eval",
359351
)

0 commit comments

Comments
 (0)