@@ -32,10 +32,10 @@ def JupyterViz(
32
32
33
33
# 1. User inputs
34
34
user_inputs = {}
35
- for k , v in model_params_input .items ():
36
- user_input = solara .use_reactive (v ["value" ])
37
- user_inputs [k ] = user_input .value
38
- make_user_input (user_input , k , v )
35
+ for name , options in model_params_input .items ():
36
+ user_input = solara .use_reactive (options ["value" ])
37
+ user_inputs [name ] = user_input .value
38
+ make_user_input (user_input , name , options )
39
39
40
40
# 2. Model
41
41
def make_model ():
@@ -142,29 +142,44 @@ def check_param_is_fixed(param):
142
142
return True
143
143
144
144
145
- def make_user_input (user_input , k , v ):
146
- if v ["type" ] == "SliderInt" :
145
+ def make_user_input (user_input , name , options ):
146
+ """Initialize a user input for configurable model parameters.
147
+ Currently supports :class:`solara.SliderInt`, :class:`solara.SliderFloat`,
148
+ and :class:`solara.Select`.
149
+
150
+ Args:
151
+ user_input: :class:`solara.reactive` object with initial value
152
+ name: field name; used as fallback for label if 'label' is not in options
153
+ options: dictionary with options for the input, including label,
154
+ min and max values, and other fields specific to the input type.
155
+ """
156
+ # label for the input is "label" from options or name
157
+ label = options .get ("label" , name )
158
+ input_type = options .get ("type" )
159
+ if input_type == "SliderInt" :
147
160
solara .SliderInt (
148
- v . get ( " label" , "label" ) ,
161
+ label ,
149
162
value = user_input ,
150
- min = v .get ("min" ),
151
- max = v .get ("max" ),
152
- step = v .get ("step" ),
163
+ min = options .get ("min" ),
164
+ max = options .get ("max" ),
165
+ step = options .get ("step" ),
153
166
)
154
- elif v [ "type" ] == "SliderFloat" :
167
+ elif input_type == "SliderFloat" :
155
168
solara .SliderFloat (
156
- v . get ( " label" , "label" ) ,
169
+ label ,
157
170
value = user_input ,
158
- min = v .get ("min" ),
159
- max = v .get ("max" ),
160
- step = v .get ("step" ),
171
+ min = options .get ("min" ),
172
+ max = options .get ("max" ),
173
+ step = options .get ("step" ),
161
174
)
162
- elif v [ "type" ] == "Select" :
175
+ elif input_type == "Select" :
163
176
solara .Select (
164
- v . get ( " label" , "label" ) ,
165
- value = v .get ("value" ),
166
- values = v .get ("values" ),
177
+ label ,
178
+ value = options .get ("value" ),
179
+ values = options .get ("values" ),
167
180
)
181
+ else :
182
+ raise ValueError (f"{ input_type } is not a supported input type" )
168
183
169
184
170
185
def make_space (model , agent_portrayal ):
0 commit comments