Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Assining JS function to HTML button

Hello there,

I am trying to use some JS to toggle a table in my dash applicaiton.
I am a bit confused since there does not seem to be an option for that. For instance there is no onClick html property:
Allowed arguments: children, id, n_clicks, autoFocus, disabled, form, formAction, name, type, value, accessKey, className, contentEditable, contextMenu, dir, draggable, hidden, lang, spellCheck, style, tabIndex, title

I guess I could achieve similar functionality with a callback but what if I wanted to assign a JS function to an html buttion/link?

Thanks!

@pgaref - It’s not possible to do that right now. For now, your options include:

In the future, there might be a couple other options:

# Python interface
JSComponent(src='''
function(input) {
    return {a: input.a*5}t;
}
''', input={'a': 3})
# JS Component Code 
class JSComponent extends Component() {
    constructor(props) {
        super(props)
    }
    componentWillReceiveProps(newProps) {
        newProps.updateProps({output: eval(newProps.src)(newProps.input)});
    }
    render() {
        return null;
    }
}
2 Likes