# How do I instantiate a class object without it being a global variable?

**URL:** <https://community.plotly.com/t/how-do-i-instantiate-a-class-object-without-it-being-a-global-variable/86809>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [August 25, 2024, 2:50pm UTC](https://community.plotly.com/t/how-do-i-instantiate-a-class-object-without-it-being-a-global-variable/86809 "2024-08-25T14:50:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonsusanto](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jasonsusanto](https://community.plotly.com/u/jasonsusanto)\
**Post date:** [August 25, 2024, 2:50pm UTC](https://community.plotly.com/t/how-do-i-instantiate-a-class-object-without-it-being-a-global-variable/86809/1 "2024-08-25T14:50:52Z")

</div>

Hi there,

I am building an input form that takes in the user input and store the inputs within the class. And upon user clicking submit, I then turn the input class into a json object. This worked perfectly in local but when I deployed my app on Azure, it seems to have issues, not sure why but I think it could be due to the Input class being a global variable, and hence when user is changing the input form and clicking save, it is instead saving different values and not the intended ones.

My inputclass.py:

class InputClass:  
def **init** (self, a: Optional[str], b: Optional[str]):  
self.a = a  
self.b = b  
def \_set\_a(self, a: Optional[str]):  
self.a = a  
def \_set\_b(self, b: Optional[str]):  
self.b = b  
… other methods

And my page.py:

from inputclass import InputClass

input\_store = InputClass(  
a=“something\_a”,  
b=“something\_b”,  
)

layout = dmc.Grid(  
children=[  
dmc.GridCol(  
children=input\_form(input\_object),  
…  
),…  
]  
)

@callback(  
Input(“input\_a”, “value”)  
)  
def change\_a(value):  
input\_store.\_set\_a(value)

and other callbacks here…

But this code seems to have issues when deployed or hosted on Azure but locally it runs perfectly fine. Is there a way to avoid this sharing of global variable? I would like such that each user has their own session and they could fill their inputs independantly. Such that each web app instance opened on browser is its separate web app independant state/session.

Any tips or suggestions would be really helpful. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [August 25, 2024, 3:14pm UTC](https://community.plotly.com/t/how-do-i-instantiate-a-class-object-without-it-being-a-global-variable/86809/2 "2024-08-25T15:14:39Z")

</div>

Hi @jasonsusanto

Have you tried an All-In-One component?

> **[All-in-One Components | Dash for Python Documentation | Plotly](https://dash.plotly.com/all-in-one-components)**
>
> The All-in-One Component Pattern allows for easy reuse of interactive components with callbacks across your apps.

---

<div class="post-metadata">

**Author:** ![jasonsusanto](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jasonsusanto](https://community.plotly.com/u/jasonsusanto)\
**Post date:** [August 25, 2024, 11:28pm UTC](https://community.plotly.com/t/how-do-i-instantiate-a-class-object-without-it-being-a-global-variable/86809/3 "2024-08-25T23:28:36Z")

</div>

Hi AnnMarieW,

Thanks for the reply. I have not tried an All-in-One component yet. I am still new to coding in python as well (usually coding in React TS, hence implementing similar concepts in Dash python, thought it would work 😅). Can I know why would the all-in-one component be useful in this scenario? And would it be possible otherwise to have the instantiation of the input\_store = InputClass(…) under a function and save it in a dcc.Store()? Would this be possible or would it be better if I use the All-in-One component for input form handling? Lastly, the input form that I will be using would just be for a single page in the app.

Cheers!

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [August 26, 2024, 12:22pm UTC](https://community.plotly.com/t/how-do-i-instantiate-a-class-object-without-it-being-a-global-variable/86809/4 "2024-08-26T12:22:06Z")

</div>

The AIO component is a way to bundle s components and callbacks in way that can be easily reused. To see an example see this post - it look similar to what you are trying to do:

> [@Dash pydantic form](https://community.plotly.com/t/dash-pydantic-form/84435):
>
> Hi all wave I have created a package to make it easy to create and validate forms with Dash and Pydantic: [dash-pydantic-form](https://github.com/RenaudLN/dash-pydantic-form) It leverages Pydantic 2 and dash mantine components (0.14) for the heavy lifting and allows auto-generated, customisable forms. Update: here is the link to [the docs site](https://pydf-docs.onrender.com) Some of its features include: Handling of nested models and list of nested models Form sections Conditional visibility Retrieval of the whole form data from a single entrypoint Here is an example o…
