@@ -246,24 +246,49 @@ def add_molecules(
246246 if isinstance (mol_col , str ):
247247 mol_col = [mol_col ]
248248
249- if mol_col is not None and len (mol_col ) > 1 :
249+ if mol_col is not None :
250+ if len (mol_col ) > 1 :
251+ menu = dcc .Dropdown (
252+ options = [{"label" : x , "value" : x } for x in mol_col ],
253+ value = mol_col [0 ],
254+ multi = True ,
255+ id = "smiles-menu" ,
256+ placeholder = "Select a mol column to display" ,
257+ )
258+ else :
259+ menu = dcc .Dropdown (
260+ options = [{"label" : mol_col , "value" : mol_col }],
261+ value = mol_col ,
262+ multi = False ,
263+ id = "smiles-menu" ,
264+ disabled = True ,
265+ )
266+ elif smiles_col is not None :
267+ if len (smiles_col ) > 1 :
268+ menu = dcc .Dropdown (
269+ options = [{"label" : x , "value" : x } for x in smiles_col ],
270+ value = smiles_col [0 ],
271+ multi = True ,
272+ id = "smiles-menu" ,
273+ placeholder = "Select a SMILES column to display" ,
274+ searchable = True ,
275+ )
276+ else :
277+ menu = dcc .Dropdown (
278+ options = [{"label" : smiles_col , "value" : smiles_col }],
279+ value = smiles_col ,
280+ multi = False ,
281+ id = "smiles-menu" ,
282+ disabled = True ,
283+ )
284+ else :
250285 menu = dcc .Dropdown (
251- options = [{"label" : x , "smiles_value" : x } for x in mol_col ],
252- value = mol_col [0 ],
253- multi = True ,
286+ options = None ,
287+ value = None ,
254288 id = "smiles-menu" ,
255289 placeholder = "Select a mol column to display" ,
290+ disabled = True ,
256291 )
257- elif smiles_col is not None and len (smiles_col ) > 1 :
258- menu = dcc .Dropdown (
259- options = [{"label" : x , "smiles_value" : x } for x in smiles_col ],
260- value = smiles_col [0 ],
261- multi = True ,
262- id = "smiles-menu" ,
263- placeholder = "Select a SMILES column to display" ,
264- )
265- else :
266- menu = dcc .Store (id = "smiles-menu" , data = 0 )
267292
268293 fig_copy = go .Figure (fig )
269294 fig_copy .update_traces (hoverinfo = "none" , hovertemplate = None )
@@ -286,22 +311,22 @@ def add_molecules(
286311 ],
287312 inputs = [
288313 Input ("graph-basic-2" , "hoverData" ),
289- Input ("smiles-menu" , "smiles_value " ),
314+ Input ("smiles-menu" , "value " ),
290315 ],
291316 )
292- def display_hover (hoverData , smiles_value ):
317+ def display_hover (hoverData , value ):
293318 if hoverData is None :
294319 return False , no_update , no_update
295320
296- if smiles_value is None :
321+ if value is None :
297322 if mol_col is not None :
298- smiles_value = mol_col
323+ value = mol_col
299324 elif smiles_col is not None :
300- smiles_value = smiles_col
301- if isinstance (smiles_value , str ):
302- chosen_smiles = [smiles_value ]
325+ value = smiles_col
326+ if isinstance (value , str ):
327+ chosen_smiles = [value ]
303328 else :
304- chosen_smiles = smiles_value
329+ chosen_smiles = value
305330
306331 pt = hoverData ["points" ][0 ]
307332 bbox = pt ["bbox" ]
0 commit comments