🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

How to add javascript snippet into my app?

Hi all.

I just wanted to reply that I had the same issue and I solved it by creating an event listener to listen for clicks, then run a function to show/hide a div if a header was clicked:

function toggle(id) {
    var state = document.getElementById(id).style.display;
    if (state == 'block') {
        document.getElementById(id).style.display = 'none';
    } else {
        document.getElementById(id).style.display = 'block';
    }
}

window.addEventListener("click", () => {
    let thedesctitle = document.getElementById('purpose-title');
    thedesctitle.setAttribute("onclick","toggle('purpose-div');");
});

I hope this helps you all with adding JS functions to Dash/Plotly apps!

Edit: I changed the ‘setAttribute’ line.