Calling JavaScript function from plotly dash

Hi,

I have a JavaScript function in HTML file. I need to call the function from plotly dash using python… Is there any way to do that…

Thanks

Hello @surr2025,

Yes, are you going to be using a button or you want this to trigger on load?

If via a button, you can do this:

app.clientside_callback(
"""function (i) {
    if (i) {
        yourfunction()
}
return window.dash_clientside.no_update
}""",
Ouput('buttonid','id'),
Input('buttonid','n_clicks')
)

You’ll need to make sure your javascript function is in your assets folder to be loaded if it isnt already.

1 Like