# dcc.Store query

**URL:** <https://community.plotly.com/t/dcc-store-query/69966>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [November 16, 2022, 6:44pm UTC](https://community.plotly.com/t/dcc-store-query/69966 "2022-11-16T18:44:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrSmith69](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@DrSmith69](https://community.plotly.com/u/DrSmith69)\
**Post date:** [November 16, 2022, 6:44pm UTC](https://community.plotly.com/t/dcc-store-query/69966/1 "2022-11-16T18:44:16Z")

</div>

Hi All,

I have a query before i entirely break my app, the question relates to the dcc.Store functionality.

Currently I have some nasty callbacks which run through mass lines of IF statements due to the multiple inputs - for example this is how one of my callbacks inputs and outputs looks:

```auto
@callback(
    Output("g1", "children"),
    Output("g1", "className"),
    Output("g2", "children"),
    Output("g2", "className"),
    Output("gcol", "className"),
    Output("gcol2", "className"),
    Input("name", "value"),
    Input("name2", "value"),
    Input("v_name", "value"),
    Input("v_name2", "value"),
    Input("l_name", "value"),
    Input("l_name2", "value"),
    Input("t", "value"),
    Input("t2", "value"),
)

```

Now this callback does if checks on every single combination of those inputs and this results in a callback that is over 2000 lines long - which is ridiculous.

I want to refactor this and first question is: Is dcc.Store the right/best way to refactor it?

Secondly the idea for the dcc.Store utilization would be the following:

1. Create a dcc.Store for v\_name which makes use of the name Dataframe
2. Create a dcc.Store for l\_name which makes use of a dataframe created out of step 1 above
3. Create a dcc.Store for t which makes use of a dataframe created out of step 2 above
4. replace all inputs on the above callback with the dataframe created out of step 3 above therefore eliminating all IF loop combos on the callback and taking it from 2000 lines to roughly 20-30

Can someone advise if this is best practise/the right way to do it and also could you perhaps provide a simple example of how to move from step 1 to step 2 - would be much appreciated!

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [November 16, 2022, 6:50pm UTC](https://community.plotly.com/t/dcc-store-query/69966/2 "2022-11-16T18:50:58Z")

</div>

Hello @DrSmith69,

That could be a way, or you might be able to use Pattern-Matching:

> **[Pattern-Matching Callbacks | Dash for Python Documentation | Plotly](https://dash.plotly.com/pattern-matching-callbacks)**
>
> The pattern-matching callback selectors \`MATCH\`, \`ALL\`, & \`ALLSMALLER\` allow you to write callbacks that respond to or update an arbitrary or dynamic number of components. New in Dash 1.11.0!

Pattern-matching would allow you to pull all the values necessary and you could set up different combos or whatnot for your other functions.

It’s hard to really say without seeing a ton of what you are trying to accomplish.

---

<div class="post-metadata">

**Author:** ![DrSmith69](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@DrSmith69](https://community.plotly.com/u/DrSmith69)\
**Post date:** [November 16, 2022, 7:20pm UTC](https://community.plotly.com/t/dcc-store-query/69966/3 "2022-11-16T19:20:08Z")

</div>

Yeah I know it is tough without seeing how it all functions - only problem with the matching etc is that all of my inputs can either work in conjunction or as standalone inputs, so there is a potentially for all of them to be None and therefore the Data Frame remains untouched, or 1 of them could be chosen which limits the DF or even 2 could be chosen, plus they are also all dynamic off of each other so if I select and option from 1 it limits the options in the 2nd one and vice versa

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [November 16, 2022, 7:26pm UTC](https://community.plotly.com/t/dcc-store-query/69966/4 "2022-11-16T19:26:39Z")

</div>

I think that you can probably manage it through pattern-matching as well.

Either way, is going to be tricky.

One of my favorite ways of dealing with stuff is by creating a dictionary of the opts and functions.

```auto
myDict = {'opt1': func1(), 'opt2': func2(), 'criteria1': func3()}

```

Then instead of using if statements, you just return the function that matches the criteria by:

```auto
return myDict[opts]

```

* * *

Also, another tip, if you set the function up to be a variable, you can pass arguments to it like you are calling the function:

```auto
myFunc = myDict[opts]

return myFunc(*args)

```
