Password protection in Dash

You may have deployed some not-for-public-consumption content on a public dashboard created using dash. In order to make sure that your dashboard is only visible to the eyes meant to see them, you can use authentication within dash.

The following simple steps help you implement basic authentication in dash.

Step 1: Import dash_auth

Add the following import statement in your python script:

import dash_auth

Also, add dash_auth to your requirements.txt file

Step 2: Create a dictionary of allowed username and passwords

Create a dictionary similar to the following:


VALID_USERNAME_PASSWORD_PAIRS = {
    'user1': 'password1', 
    'user2': 'password2'
}

Step 3: Add authentication after the creation of the app

The authentication syntax looks like the following:

app = dash.Dash()
server = app.server
auth = dash_auth.BasicAuth(
     app,
     VALID_USERNAME_PASSWORD_PAIRS
 )

That’s it. Now whenever someone tries to access this dashboard, they will have to enter a valid username and password.

If they click cancel, they won’t be allowed to proceed further.

That’s it. These are all the steps you need to implement password protection on your dash application.

If you wish to learn how to deploy a dash app on Heroku, check out this article.


Found this post helpful? Then check out further posts on iotespresso.com. Also, follow IoT Espresso on Twitter to get notified about every new post.

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *