Redis in Dash: maximum recursion level reached

I am building a Dash application in Python 3.7. Specifically, I want to use redis for pre-computing an entire figure, but get an error “Maximum recursion level reached.”

I follow “Example 4”, “Part 6, Sharing Data Between Callbacks” of the official Dash Tutorial ( However, in contrast to that example, I want to pre-compute not some data, but the entire figure. That is because I receive large datasets – meteorological data over time – that load very slowly because of their size, and hence I thought of pre-computing the figure beforehand. Anyway, I can built the app without the precompute part, but trying to modify it throws that error message from deep inside the Dash engine.

import os, sys, uuid
import dash_core_components as dcc
import dash_html_components as html
import dash
import plotly
from flask_caching import Cache
import pandas
import numpy

sys.setrecursionlimit(500000) # doesn’t help!

N = 50000 # big number

start Dash application

app = dash.Dash(name)
cache = Cache(app.server, config={
‘CACHE_TYPE’: ‘redis’,
‘CACHE_DIR’: ‘cache-directory’,
‘CACHE_REDIS_URL’: os.environ.get(‘REDIS_URL’, ‘redis://localhost:6379’),

def get_dataframe(session_id):
def query_and_serialize_data(session_id):
prep = pandas.DataFrame({
‘data’: [plotly.graph_objs.Scattergl(
x=[index for index in range(0, N)], # time index
y=numpy.random.rand(N), # data points
return prep.to_json()
return pandas.read_json(query_and_serialize_data(session_id))

def serve_layout():
session_id = str(uuid.uuid4())
return html.Div([
# hidden
html.Div(session_id, id=‘session-id’, style={‘display’: ‘none’}),
# graph

app.layout = serve_layout

update graph

dash.dependencies.Output(‘graph’, ‘figure’),
[dash.dependencies.Input(‘session-id’, ‘children’)])
def update_graph_figure(session_id):
#data = [plotly.graph_objs.Scattergl(
# x=[index for index in range(0, N)], # time index
# y=numpy.random.rand(N), # data points
# mode=‘lines+markers’
#)] # valid data to ‘graph’
prep = get_dataframe(session_id)
return {‘data’: prep[‘data’]}

main program

if name == ‘main’:

The error message:

Traceback (most recent call last):
File “C:\ProgramData\Anaconda3\lib\site-packages\flask\”, line 2309, in call return self.wsgi_app(environ, start_response)

File “C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\json\”, line 161, in _write iso_dates, default_handler)
File “C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\json\”, line 115, in _write default_handler=default_handler
OverflowError: Maximum recursion level reached

How should I correct the code? And if the very idea does not work, how can I speed up the load time in some other way?