✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Dash webapps in dataiku

The dataiku ecosystem integrates with Shiny and Bokeh, but not Dash. From version 0.0.44, dash-extensions enables easy integrations of Dash apps as webapps in dataiku.

To get started, create a standard webapp. Make sure that the selected code environment (can be configured in the Settings tab) has the following packages installed,

dash==1.18.1
dash-extensions==0.0.44

Replace the content of the HTML tab with

<head>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/thedirtyfew/dash-extensions@0.0.44/snippets/dataiku.js"></script>
</head>

and clear the JS and CSS tabs (unless you the JS/CSS code). Finally, go to the Python tab and replace the content with

import dash
import dash_html_components as html
from dash_extensions.dataiku import setup_dataiku

# Path for storing app configuration (must be writeable).
config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json")
# Create a small example app.
dash_app = dash.Dash(__name__, **setup_dataiku(app, config_path))
dash_app.layout = html.Div("Hello from Dash!")

After clicking save, you should see the text Hello from Dash! in the preview window (a backend restart might be required). Congratulations! You have created you first Dash app in dataiku.

1 Like

@Emil This works like a charm - thanks so much for creating and sharing this!

There is an error I am facing, please review and let me know if you have any ideas on how to solve it. Others might benefit as well. Thanks in advance!

I run my Dash app in Dataiku as a web app, and I have been trying to simplify my somewhat large file by using a flat project layout with callbacks and layouts separated into different files, as explained towards the bottom of https://dash.plotly.com/urls . This article basically suggests to organize the dash app in 4 python files app.py, index.py, callbacks.py, layouts.py and start it by running index.py.

In Dataiku the python file that runs a webapp is backend.py. What I did is use the code from index.py (as described in the documentation link above) in my backend.py, and I import the other 3 files from a python library I created in Dataiku. Your code goes into the file app.py, except from the last line, which goes into layouts.py

So far so good, but when I try to run I get this error from the app.py file (where your code is put):

image

I thought it might had to do with the config_path - I also hardcoded the config path that is returned when the app runs successfully as one backend.py file, but still could not get it to work.

I cannot figure out what is going wrong (even after studying your github code) - everything runs perfectly fine if I have all my application in 1 file (backend.py).

Any help with this would be much apprecieted. TIA

In dataiku, the code in the Python tab is executed in a context where a Flask server object denoted app is defined. The line

dash_app = dash.Dash(__name__, **setup_dataiku(app, config_path))

creates a Dash object (denoted dash_app) with the dataiku provided Flask server as backend. Hence you must create the Dash object here. If you need it in other files, can pass it along, e.g. something along the lines of

import my_app
dash_app.layout = my_app.layout
my_app.register_callbacks(dash_app)
1 Like

Thanks for the super-fast response. Great explanation, I can know see what is wrong (not being a Comp. Sc., I am not familiar with Flask details).

Cheers!

@Emil that’s really awesome, thanks for sharing this!

I have one question: I would like to add authentication to my dash app and have tried using dash-auth (Add Authentication to your Dash App | Dash for Python Documentation | Plotly). When I implemented the authentication as by the example, the backend does not respond, there is no immediate error but I receive a timeout error after some time. When running the script locally on my laptop, it works fine.

The way I have tried it is like this:

dash_app = dash.Dash(
    __name__, 
    external_stylesheets=external_stylesheets,
    **setup_dataiku(app, config_path)
)

VALID_USERNAME_PASSWORD_PAIRS = {
    'hello': 'world'
}

auth = dash_auth.BasicAuth(
    dash_app,
    VALID_USERNAME_PASSWORD_PAIRS
)

Do you have any suggestions of how I could implement authentication? Is it maybe easy enough to change the .js script that you wrote to implement dash_auth?

Thanks a lot for your help!
Oliver

Have you considered wrapping the app in a Dashboard? Then you should be able to use dataiku authentication.

Thanks for the quick reply @Emil, that’s a good suggestion but I think it doesn’t fit my use case.

My use case is that I want to make my webapp available to users without access to Dataiku. We can create public webapps within Dataiku since version 8 (Public webapps — Dataiku DSS 8.0 documentation). However, I want to add authentication to it so that it’s not available to everybody on the internet.

Hello everyone!

Jumping on this thread to share a little update: Dataiku has officially added support for Dash webapps, more info available here: DSS 9.0 Release notes — Dataiku DSS 9.0 documentation :partying_face:

1 Like

It is great! The only major issue is that you don’t have control over the app object construction :confused: