Dash¶
Beta: Please note that Dash support is a beta feature which is still undergoing final testing before its official release. Should you encounter any bugs, glitches, lack of functionality or other problems, please let us know so we can improve before public release.
Dash is a productive Python framework for building web applications. Written on top of Flask, Plotly.js, and React.js, Dash is ideal for building data visualization apps with highly custom user interfaces in pure Python. It's particularly suited for anyone who works with data in Python.
Deploying¶
Dash apps can be deployed with the
rsconnect-python
package. See the Publishing with
rsconnect-python section for
details.
Example apps¶
An example Dash app is available on GitHub.
To deploy the example with rsconnect-python
:
git clone https://github.com/sol-eng/python-examples rsconnect deploy dash -n <saved server name> --entrypoint app:app python-examples/dash-app/
There are also a number of Dash example apps available from Plotly. Some of them require Python 2 and others use Python 3; please ensure that you run them locally before deploying to Connect. Also ensure that you specify the correct entrypoint
for the specific app you are deploying.
git clone https://github.com/plotly/dash-sample-apps rsconnect deploy dash -n <saved server name> --entrypoint app:app dash-sample-apps/apps/<app name>/
User meta-data¶
Dash apps can access the username and groups of the current logged in user by
parsing the RStudio-Connect-Credentials
request header.
Most environments have unique usernames where each
username
identifies a single user. In large organizations with hundreds of users, it is possible to have two users with, for example, the same last name and initials, which could result in a duplicated username. If you're expecting such a large number of logged in users to access your Dash app, please be sure to consult your administrator to confirm whether this condition is possible in your environment.
Group meta-data is populated when using most authentication providers with the exception of LDAP. This happens because group memberships are only stored in the LDAP server.
Your Dash app should access the
RStudio-Connect-Credentials
header value via theflask.request
object'sheaders
property. This value is populated from theHTTP_RSTUDIO_CONNECT_CREDENTIALS
environment variable present in the underlying WSGI environ.
This simple Dash app shows how to access and use the user credentials from the
RStudio-Connect-Credentials
header:
# -*- coding: utf-8 -*- import json import dash import dash_core_components as dcc import dash_html_components as html import flask from dash.dependencies import Input, Output app = dash.Dash(__name__) app.layout = html.Div([ dcc.Dropdown( id="salutation", options=[ {"label": "Hello", "value": "Hello"}, {"label": "Greetings", "value": "Greetings"}, {"label": "Aloha", "value": "Aloha"}, ], searchable=False, clearable=False, value="Hello" ), html.P(id="greeting") ]) def get_credentials(req): """ Returns a dict containing "user" and "groups" information populated by the incoming request header "RStudio-Connect-Credentials". """ credential_header = req.headers.get("RStudio-Connect-Credentials") if not credential_header: return {} return json.loads(credential_header) @app.callback( Output(component_id="greeting", component_property="children"), [Input("salutation", "value")] ) def greeting(salutation): user_metadata = get_credentials(flask.request) username = user_metadata.get("user") return "%s, %s." % (salutation, username or "stranger") if __name__ == "__main__": app.run_server(debug=True)