Black Lives Matter. Please consider donating to Black Girls Code today.

Render dash app layout based on incoming POST request

I’m looking to create a dash based graph service serving multiple clients at a time where dash layout can be dynamically created / updated. I understand that dash doesn’t have this kind of ‘push’ functionality so I created a route using dash server and tried to pass the body of POST request to dash app by defining a serve_layout function. But the app doesn’t reload. Following is part of the relevant code:

@server.route(’/draw’, methods = [‘POST’])
def result():
if request.method == ‘POST’:
return render_template(“index.html”)

def serve_layout(post_body):
# Construct layout

dash_app.layout = serve_layout

Any suggestions on how to proceed? Thanks in advance.

What kind of changes do you need to make to the layout via the POST request?

More than the changes, the primary goal is to create multiple layouts, one for each POST request and keep track of user interactions with the layout. In essence layout-renderer-as-a-service.

There was some limited discussion about pub-sub and a React based web-socket receiver. If someone took a lot of the complexity out of this it would solve your requirement of a web server initiated refresh on a callback that watched for new data on the socket. Here is a link to one of those discussions :slight_smile:

I know this doesn’t answer your question but that would make dashboarding in DASH next level.


Thanks for the pointer. At least makes me feel better about other people being in a similar boat. :laughing:

1 Like