kcompher / dash-redis-demo

Connect to Redis from Dash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dash Redis Demo

This app demonstrates how to connect to a Redis database from Dash.

It works out of the box with the Redis server built in to Dash On Premise but could be adapted to work with other servers such as Heroku Redis or your local Redis server.

For debugging convenince, we install the redis-tools package, which offers the redis-cli command. This can be removed for faster app push times.

Enable Redis Databases for Dash App

In Plotly Enterprise 2.5.0, Redis Databases are always enabled.

For previous versions, you need enable Redis. To achieve this, navigate to the settings page of the Server Manager. Under Special Options & Customizations select Enable Dash Customizations and then select Enable Redis Databases for Dash Apps. For more information see our official documentation on Redis.

Create and Link a Redis Database on Plotly Enterprise

In Plotly Enterprise 2.5.0, you can create and link a Redis Database using the Dash Deployment Server UI. For more information see our official documentation on Redis.

If you are using Plotly Enterprise 2.4.0, you can follow the ssh commands below:

ssh dokku@YOUR_DASH_SERVER redis:create SERVICE-NAME
ssh dokku@YOUR_DASH_SERVER redis:link SERVICE-NAME APP-NAME

In the commands above, replace:

  • YOUR_DASH_SERVER with the name of your Dash server (same as when you run git remote add)
  • SERVICE-NAME with the name you want for your Redis service
  • APP-NAME with the name of your app (as specified in the Dash App Manager).

Celery

This app also includes the Celery task queue and a sample task.

Clicking the Run "Hello" task button runs the task asynchronously. The task sleeps for 10 seconds then writes the current date and time to a file.

In order to run Celery tasks, a broker needs to be run. To do this, scale up your app's "worker" process after pushing it:

ssh dokku@YOUR_DASH_SERVER ps:scale APP-NAME worker=1

As above, replace APP-NAME with the name of your app.

To verify that the broker is working correctly, check your app's logs after clicking the button a few times:

ssh dokku@YOUR_DASH_SERVER logs APP-NAME

Tasks should show up in the logs when they are submitted (in other words when "Hello" is clicked), and then the task should complete about 10 seconds later.

About

Connect to Redis from Dash

License:MIT License


Languages

Language:Python 100.0%