9
9
"input_select" ,
10
10
"input_selectize" ,
11
11
)
12
- import copy
13
- from json import dumps
14
- from typing import Any , Mapping , Optional , Union , cast
12
+ import json
13
+ from typing import Mapping , Optional , Union , cast
15
14
16
15
from htmltools import Tag , TagChild , TagList , css , div , tags
17
16
@@ -263,7 +262,6 @@ def _input_select_impl(
263
262
options = {}
264
263
265
264
plugins = _get_default_plugins (remove_button , multiple , choices_ )
266
- options = _add_default_plugins (options , plugins )
267
265
268
266
choices_tags = _render_choices (choices_ , selected )
269
267
@@ -278,19 +276,16 @@ def _input_select_impl(
278
276
multiple = multiple ,
279
277
size = size ,
280
278
),
281
- (
282
- TagList (
283
- tags .script (
284
- dumps (options ),
285
- type = "application/json" ,
286
- data_for = resolved_id ,
287
- data_eval = dumps (extract_js_keys (options )),
288
- ),
289
- selectize_deps (),
290
- )
291
- if selectize
292
- else None
279
+ tags .script (
280
+ json .dumps (options ),
281
+ type = "application/json" ,
282
+ data_for = resolved_id ,
283
+ # Which option values should be interpreted as JS?
284
+ data_eval = json .dumps (extract_js_keys (options )),
285
+ # Supply and retain these plugins across updates (on the client)
286
+ data_default_plugins = json .dumps (plugins ),
293
287
),
288
+ selectize_deps () if selectize else None ,
294
289
),
295
290
class_ = "form-group shiny-input-container" ,
296
291
style = css (width = width ),
@@ -317,18 +312,6 @@ def _get_default_plugins(
317
312
return ()
318
313
319
314
320
- def _add_default_plugins (
321
- options : dict [str , Any ], default_plugins : tuple [str , ...]
322
- ) -> dict [str , Any ]:
323
- opts = copy .deepcopy (options )
324
- p : list [str ] = opts .get ("plugins" , [])
325
- if not isinstance (p , list ):
326
- raise TypeError ("`options['plugins']` must be a list." )
327
- p .extend (default_plugins )
328
- opts ["plugins" ] = p
329
- return opts
330
-
331
-
332
315
def _normalize_choices (x : SelectChoicesArg ) -> _SelectChoices :
333
316
if x is None :
334
317
raise TypeError ("`choices` must be a list, tuple, or dict." )
0 commit comments