✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Dash stripping commas and brackets of the value it returns from a dropdown

I have a dropdown in dash, like this:

import dash_core_components as dash_core
import dash_html_components as dash_html
...
dash_core.Dropdown(id="department_input_los", placeholder='--choose department--',
                   options=[{'label': 'All Departments', 'value':
                                             '[\'Gynecology\', \'Urology\', \'Nephrology\',\'Dermatology\']'},
                            {'label': 'Gynecology', 'value': 'Gynecology'},
                            {'label': 'Urology', 'value': 'Urology'},
                            {'label': 'Nephrology', 'value': 'Nephrology'},
                            {'label': 'Dermatology', 'value': 'Dermatology'},],
                   value= '[\'Gynecology\', \'Urology\', \'Nephrology\',\'Dermatology\']',
                                                                   searchable=True)
...

the problem is, when i select first option, call back returns the string stripping down all commas and brackets, like this: GynecologyUrologyNephrologyDermatology, instead of returning string inside the single quotes in value key like this:['Gynecology', 'Urology', 'Nephrology','Dermatology'] . I checked this by printing the value that this dropdown returns, to a dash_html.H6 by using a callback.

I will be converting it back to a list and filter my data and then plot a graph.
Also i cannot do multi=True, because I have another dropdown whose options will be updated by input from this option and having multi=True is really messing up the process of updating another dropdown’s options.

So, How do i have dash return me my value as it is, without stripping all commas and brackets in the value.

Hi @naveen_9697 I cannot reproduce the problem: with the following code, the value string keeps its commas and brackets. I’m using Python 3.7, which version of Python are you using?

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc

app = dash.Dash()

app.layout = html.Div([
    dcc.Dropdown(id="input", placeholder='--choose department--',
                   options=[{'label': 'All Departments', 'value':
                                             '[\'Gynecology\', \'Urology\', \'Nephrology\',\'Dermatology\']'},
                            {'label': 'Gynecology', 'value': 'Gynecology'},
                            {'label': 'Urology', 'value': 'Urology'},
                            {'label': 'Nephrology', 'value': 'Nephrology'},
                            {'label': 'Dermatology', 'value': 'Dermatology'},],
                   value= '[\'Gynecology\', \'Urology\', \'Nephrology\',\'Dermatology\']',
                                                                   searchable=True),
    html.Div(id='output')
])

@app.callback(
    dash.dependencies.Output('output', 'children'),
    [dash.dependencies.Input('input', 'value')])
def print_input(val):
    print(val)
    return val


if __name__ == '__main__':
    app.run_server(debug=True)

I am using python 3.6.8 64bit on a windows 10 laptop. I couldn’t get it to work with python 3.6. let me try with recent python version and get back to you @Emmanuelle

I first updated all of dash’s packages to recent versions and tried reproducing the issue. It was gone. May be, this was the issue with old version of dash. I didn’t try installing recent version of python though. Thanks anyway.