0

Running a standard dash-plotly app with a dropdown, I would like to simulate a click on the dropdown via javascript. The dropdown opens when I click on it via the mouse but does not respond to the JS call ($('#mydropdown.dash-dropdown').click()).

Any ideas what is going on here?

import dash
import dash_core_components as dcc
import dash_html_components as html


app = dash.Dash(__name__)
app.layout = html.Div(
    [
        dcc.Dropdown(
            id="mydropdown",
            options=[
                {"label": "New York City", "value": "NYC"},
                {"label": "Montreal", "value": "MTL"},
                {"label": "San Francisco", "value": "SF"},
            ],
            value="MTL",
            clearable=False,
        ),
    ]
)



if __name__ == '__main__':
    app.run_server(host='0.0.0.0', debug=True, port=8099)

bjonen
  • 1,503
  • 16
  • 24

1 Answers1

0

This is generally not possible anymore in Javascript due to security risks, see How can you programmatically tell an HTML SELECT to drop down (for example, due to mouseover)?.

Testing click events can be performed via Selenium instead.

bjonen
  • 1,503
  • 16
  • 24