99 "input_select" ,
1010 "input_selectize" ,
1111)
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
1514
1615from htmltools import Tag , TagChild , TagList , css , div , tags
1716
@@ -263,7 +262,6 @@ def _input_select_impl(
263262 options = {}
264263
265264 plugins = _get_default_plugins (remove_button , multiple , choices_ )
266- options = _add_default_plugins (options , plugins )
267265
268266 choices_tags = _render_choices (choices_ , selected )
269267
@@ -278,19 +276,16 @@ def _input_select_impl(
278276 multiple = multiple ,
279277 size = size ,
280278 ),
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 ),
293287 ),
288+ selectize_deps () if selectize else None ,
294289 ),
295290 class_ = "form-group shiny-input-container" ,
296291 style = css (width = width ),
@@ -317,18 +312,6 @@ def _get_default_plugins(
317312 return ()
318313
319314
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-
332315def _normalize_choices (x : SelectChoicesArg ) -> _SelectChoices :
333316 if x is None :
334317 raise TypeError ("`choices` must be a list, tuple, or dict." )
0 commit comments