This documentation is for Dash Enterprise.
Dash Enterprise is the fastest way to write & deploy Dash apps and
Jupyter notebooks.
10% of the Fortune 500 uses Dash Enterprise to productionize AI and
data science apps. Find out if your company is using Dash Enterprise.
With Dash Enterprise, you can easily create managed Redis or Postgres databases for your app. A deployed app and the app’s workspace share the same instances of a service. This enables you to inspect data used by your deployed app from within the workspace. However, it is important that you structure your code to not overwrite Redis or Postgres data unintentionally.
If you add Postgres or Redis instances after creating the workspace, you’ll need to restart the workspace to have access to them.
If you are using Celery, then it is important to write to a different Redis
database. The following code demonstrates how to define a different
REDIS_URL
depending on the environment.
if os.environ.get("DASH_ENTERPRISE_ENV") == "WORKSPACE":
next_database_number = str((int(os.environ.get("REDIS_URL")[-1]) + 1) % 16)
REDIS_URL = os.environ["REDIS_URL"][:-1] + next_database_number
parsed_url = urlparse(os.environ.get("REDIS_URL"))
if parsed_url.path == "" or parsed_url.path == "/":
i = 0
else:
try:
i = int(parsed_url.path[1:])
except:
raise Exception("Redis database should be a number")
parsed_url = parsed_url._replace(path="/{}".format((i + 1) % 16))
updated_url = parsed_url.geturl()
REDIS_URL = "redis://%s" % (updated_url.split("://")[1])
else:
REDIS_URL = os.environ.get("REDIS_URL", "redis://127.0.0.1:6379")
Note that you do not need to use this code if you are using dash-snapshots
as
dash-snapshots
manages the REDIS_URLs internally.
If you are saving to a Postgres database, consider saving to a different
table if within a workspace environment. As above, the workspace environment
can be detected with:
if os.environ.get("DASH_ENTERPRISE_ENV") == "WORKSPACE":
# This code is run within a workspace
dash-snapshots
The dash-snapshots
library implicitly saves data
to Redis and Postgres in a way that won’t overwrite the data in the deployed
application.
For Redis, dash-snapshots
uses an alternative Redis database on the
same instance if the code is run within Workspaces. Each Redis instance has 16 available databases.
For Postgres, dash-snapshots
saves to a different Postgres table
if the code is run within Workspaces.