Create a long questionnaire with Graphs dynamically

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:

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! :slight_smile:

You may like this below.

1 Like

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.