Dash Dropdown: Can Value have 2 dimensional array?

Hi,

I am using Dropdown dash component to view the data and I am stuck with Option and Value.

Example:
‘label’ has the parameter name for the dropdown display and ‘value’ has 2 dimensional array for callback. Is this feasible?
All the example I have seen states, 1 value for each label.

Hello @Akshay91,

Welcome to the community! I don’t think so with its innate state. However, you could json dump the array and json load the data to be the array in order to use in callbacks.

Hi jinnyzor,

Thank you for your quick revert & guidance. I haven’t worked with Jason but I guess I can use dictionary for the same.
So in value, I will use the key of “my_dict” and then reference the value of “my_dict” to plot.

That might work. It’s kind of hard to say without seeing your code.

If you can, post how you are populating the drop-down options.

import dash
from dash import dcc
from dash import html
from Line_plot import plot_config2, serialDate_to_datetime # Line plot created for IFS data using .mat file
from file_path import file_select
from read_dataFiles import read_mat, read_csv
from dash.dependencies import Input, Output
import plotly.graph_objs as go

app = dash.Dash()

read all the data from the matlab file

filepath = file_select()
key_list, mat_data = read_mat(filepath)

list_mat_data =
for data in mat_data:
list_mat_data.append({‘label’:data,‘value’:data})

Configure Layout

app.layout = html.Div([
dcc.Graph(id=‘graph’),
dcc.Dropdown(id=‘Select Parameter’,options=list_mat_data,multi=False,searchable=True,value=‘Msg00000201_dieselEnergy_kJ’)
])

The @app.callback decorator needs to be directly above the callback function declaration.

If there is a blank line between the decorator and the function definition, the callback registration will not be successful.

@app.callback(Output(‘graph’, ‘figure’),[Input(‘Select Parameter’,‘value’)])
def update_figure(selected_parameter):
# x,y = plot_config2(selected_parameter)
x = # list creation
temp1 = mat_data[selected_parameter]

using key to find the value from dictionary

serialTime = temp1[:,0]
for t in serialTime:
    x.append(serialDate_to_datetime(t))
y=temp1[:,1]
trace = go.Scatter(x= x, y=y, mode='lines+markers',name=selected_parameter)

return {'data':trace,
        'layout': go.Layout(hovermode='closest')}

if name == ‘main’:
app.run_server(debug=False)

I have posted my code with the image of dropdown. I am trying to solve why it is not plotting the Line plot
My current post is under review by the community admin for SPAM. I hope it gets cleared.

Summary:
I am trying to build a Dash board which can read MATLAB data files (.mat) and visualize the selected parameters.
I am able to read, plot the signals individually or if I give specific parameter name. I learned about Dash from an Udemy course and started implementing interactive plots in which I can select the parameters from the drop down and the plots get updated with the selection.

Regards
Akshay91

I found the issue. I needed a hi-fi on my face ! :dizzy_face:

return { ‘data’: [trace], …}

It has to be a list !

The real issue is, that even in debug mode, the control doesn’t goes inside the def update_figure() function so I never understood why it is not displaying.

@jinnyzor Thanks for your reverts!

1 Like