I was wondering if there’s a way to have user inputted data be stored server side so it would influence all other users accessing the dashboard. Specifically, I have a dashboard that includes and upload function where I user can upload a markdown file that is written into a text box within the app. This is done by passing the decoded markdown file through dcc.store, which is then passed through to the core markdown component. Only one admin user can upload files with this method via built in credentials within the markdown file. However, other users aren’t able to view the updated text after it has been uploaded. I presume this is because the text is being stored within the admin users browser. Is there any way to set either dcc.store or dcc.Markdown (or any other method) to ensure that uploaded markdown files and the text within are visible to all users that may access the app?
Welcome to the community!
There are a few ways to do it and it boils down to 1) how robust should the solution be and 2) where you have it deployed.
The simplest approach in my view would be to open the uploaded file in a callback and serve it in the
dcc.Markdown component for all users. This of course relies on the server filesystem (in principle) or wherever you are storing the updated data.
Due to the RESTful nature of Dash, you won’t be able to “push” changes to the users, so whether you have to use a
dcc.Interval component to trigger the update from time to time or the user has to reload the page to update it.
This would be the first approach that I would try, given that this file is not updated often and it doesn’t seem to be a risk of racing conditions (two users trying to write the file simultaneously).
Hope this helps! Otherwise, please follow up.
Am I mistaken in saying that there could be a callback that is linked to a websocket server for relaying information between clients? I think I had seen a user-created library to make that kind of thing possible.
Yes, that would be possible. It’s slightly more complicated to setup though.
The simplest would probably be to save the data (files) to a server side cache (e.g. Redis) when the admin uploads, and then read it from cache when clients view the application (and poll updates if necessary).
Since our app is hosted on AWS, I went with your suggestion and had the upload component decode and serialize the data to our S3 storage bucket. Then, I created a second function that downloads the file and passes it through to the dcc.markdown component whenever a new file is uploaded. Seemed to do the trick!
That sounds like a good solution