Hi,
I am facing an issue with my Dash web app which works and runs perfectly locally, but when the same code and its dependencies are deployed to Azure, it is behaving differently. Mostly circulating towards the callbacks.
For context, I am building an input form which is quite complex. The input form has the following structure:
input_object = InputClass(
a=default_value,
b=default_value,
…
)
layout = dmc.Grid(
children=[
dmc.GridCol(
children=input_form(input_object),
…
),…
]
)
… Callbacks here
And within my input_form function:
First row: general inputs (Simple callback, listens to the input ID and saves the value inputted to the input_object)
Second row: Accordion (4 constant accordion items that have nested accordion items within it) E.g.:
First Accordion:
1. First Nested Accordion: (Within this accordion users can add inputs)
2. Second Nested Accordion: (Users can add inputs)
Second Accordion:
Has the same nested accordion items But should be distinct based on the parent accordions
But seems like I am facing this issue only when deployed code to cloud. But when I am running locally and deployed, it runs with the same flow of:
if name == ‘main’:
app.run(debug=True, port=8000)
Can anyone please give insights why the callbacks and class usage in Dash plotly is behaving differently in local and cloud?
Just based on what turned out to be the issue in a recent similar question here that’s stuck in my mind, are you absolutely sure you have the same versions of all packages in the cloud install as you have locally?
Just glancing at your code, I think you’re probably running DMC 0.13 or earlier locally (you’d need a dmc.MantineProvider() in your layout for 0.14), and it would go wrong if the cloud deploy has used the current release of DMC.
(But if you are using DMC 0.14 have you remembered to set React version 18.2.0 in your cloud deployment?)
Hi David, thanks for the reply. Yes I am absolutely sure the package versions are the same and correct as I have been deploying to the app before and it was working. Just that after implementing this new page and feature it is having issue. The issue is that its not failing, rather, the app I believe is sharing values? I was just doing some research and reading, is the way I instantiated my InputClass wrong? As in could it be a global variable that seems to be shared by dash across all users?
this_page.py:
imports …
dash.register_page(name, path=‘/this-page’, title=‘This page’,
order=15)
input_object = InputClass(
a=default_value,
b=default_value,
…
)
layout = dmc.Grid(
children=[
dmc.GridCol(
children=input_form(input_object),
…
),…
]
)
callbacks here …
And this is the InputClass.py:
class InputClass:
def init(self, a: Optional[str] = None, b: Optional[str] = None, …
):
self.a = a
self.b = b
The ultimate issue I am getting is that when I refresh this page: ‘/this-page’ URL, it does not make a new class of InputClass(…), could this be an issue with session being shared etc.? As it is working perfectly locally and not when deployed. But I can confirm it has nothing to do with versions and packages installed.
It sounds to me like you have identifed your problem. (If you have you should also see the same issue if you open more than one browser session simultaneously on your local instance)
I think the code fragments you’ve posted do suggest that one InputClass object (and its properties) will be shared across all sessions - you maybe need to create a new InputClass object within the callback or something like that?
You probably already know this link, but if not it’s essential reading:
1 Like
Hi @davidharris , thanks for the link! Yes I just tried duplicating the localhost instance in my browser and also a different browser and it is using the same class, hence sharing the data of the InputClass. I have also just read about the sharing data between callbacks (sorry, I’m new to Dash and Python - used to code mostly with React and TS), and would this mean that I should instantiate InputClass in a function and save it in a dcc.Store()? Would this allow each user session to be unique and unshared?
Thanks a lot!
Yes, that sounds like exactly the solution. The data in a dcc.Store() is held in the browser, so separately for each user.