# Create a long questionnaire with Graphs dynamically

**URL:** <https://community.plotly.com/t/create-a-long-questionnaire-with-graphs-dynamically/62409>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [March 28, 2022, 11:45pm UTC](https://community.plotly.com/t/create-a-long-questionnaire-with-graphs-dynamically/62409 "2022-03-28T23:45:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert\_oc](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/robert_oc/32/18569_2.png) [@robert\_oc](https://community.plotly.com/u/robert_oc)\
**Post date:** [March 28, 2022, 11:45pm UTC](https://community.plotly.com/t/create-a-long-questionnaire-with-graphs-dynamically/62409/1 "2022-03-28T23:45:57Z")

</div>

I have to create a questionnaire with 58 questions divided in 5 sections. Not all sections are the same length one has 22 questions, other has 5.

I have created a layout where each section is in a Card from dash-boostrap-components and at the end of each section there is a Graph that will collect the values of the radio items used for answers. Like this:

 ![Section](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/8/684edd2a2051ac48cbb9cd91db2e3bb597ed5d36.png)

However, I have two questions:

The first one is, if there is a better way to do this than writing the same code 5 times for the sections an 58 times for the questions. I’m going to store the results to a database, so I can create a table with the sections and another with the questions but I’m not sure if I can create the code dynamically and then add the results to the layout? Could someone point out if that’s possible and direct me to an example?

The second one is about collecting the values of the radio items, the form has to have a “Send” button and after is “pressed” collect the values of all the answers to finish the Graphs adding a second column “Resultado”, I can declare all the radio items values as Inputs in the Callback for the button but I’m wondering if there’s another way to that.

Thank you for your help! 🙂

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/stu/32/18439_2.png) [@stu](https://community.plotly.com/u/stu)\
**Post date:** [March 29, 2022, 2:01am UTC](https://community.plotly.com/t/create-a-long-questionnaire-with-graphs-dynamically/62409/2 "2022-03-29T02:01:57Z")

</div>

You may like this below.

> **[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!

---

<div class="post-metadata">

**Author:** ![robert\_oc](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/robert_oc/32/18569_2.png) [@robert\_oc](https://community.plotly.com/u/robert_oc)\
**Post date:** [April 4, 2022, 10:36pm UTC](https://community.plotly.com/t/create-a-long-questionnaire-with-graphs-dynamically/62409/3 "2022-04-04T22:36:37Z")

</div>

Thanks for the link!

Sadly, I ended collecting all elements because Pattern-Matching callbacks didn’t get me the results I wanted. Maybe I made a mistake with the coding and that’s why it didn’t work, but now I have a callback with all the values of radio buttons as State.

On the bright side, I found a way to generate the layout with functions (yes I’m still new in Dash and in Python) so the app file is not too big even with all that State in the callbacks.
