Use variables define in Bokeh webapp as DSS global variables

wdpat20
wdpat20 Registered Posts: 2 ✭✭✭✭

It is my first use of Bokeh Webapp.

I would like to define DSS global variables from Bokeh Webapp.

example :

CODE_OP = TextInput(title="code operation", value='')

CODE_DIFF = TextInput(title="code(s) diffusion(s)", value='')

I want to use CODE_OP and CODE_DIFF as DSS variables in the recipies of my project flow and scenario.

Tagged:

Best Answer

  • tim-wright
    tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner
    edited July 17 Answer ✓

    @wdpat20
    I'm not 100% sure what you are trying to accomplish (more generally beyond setting variables) so I can't be sure that this will help you in that ultimate goal. That being said, I fooled around with a bokeh webapp recently and have a working example of what I think you want - the entire trivial webapp code is pasted below. I have one text box changing a local variable, adn the other a global variable just to show how its done - modify as needed.

    import dataiku
    
    from bokeh.io import curdoc
    from bokeh.layouts import row, widgetbox
    from bokeh.models.widgets import TextInput
    
    # Getting the project variables for this project using Public API
    proj = dataiku.api_client().get_project(dataiku.default_project_key())
    variables = proj.get_variables()
    
    # Set up widgets
    CODE_OP = TextInput(title="code operation", value='')
    CODE_DIFF = TextInput(title="code(s) diffusion(s)", value='')
    
    # Callbacks 
    # Change CODE_OP Local variable for this project (creates if it didn't exist)
    def update_code_op(attrname, old, new):
        variables['local']['CODE_OP'] = new
        proj.set_variables(variables) # Using Dataiku API to update project variables
        
    CODE_OP.on_change('value', update_code_op)
    
    # Change CODE_DIFF Global variable for this project (creates if it didn't exist)
    def update_code_diff(attrname, old, new):
        variables['standard']['CODE_DIFF'] = new
        proj.set_variables(variables) # Using Dataiku API to update project variables
        
    CODE_DIFF.on_change('value', update_code_diff)
    
    
    # Set up layouts and add to document
    inputs = widgetbox(CODE_OP, CODE_DIFF)
    curdoc().add_root(row(inputs, width=800))
    curdoc().title = "Update Project Vars"

    I would imagine you might want a "Run Analysis" button or something below that allows the project flow to be run with those parameters from the Bokeh application? (that will probably require a button with an .on_click callback that triggers other actions through the DSS API). If this is meant for a user, it may have substantial latency for user interaction (waiting for the flow to execute). Additionally if you are expecting concurrency (multiple simultaneous users) you may find that they are trying to overwrite each other's results.

    @wdpat20
    , Let me know if this answered your need. Also, when you get your full use case working, I encourage you to share here so the rest of us can benefit from your trailblazing! Have a good weekend.

Answers

Setup Info
    Tags
      Help me…