Efficient Code Reuse in Dash Web Applications

Hello everyone,

I’m relatively new to Dash in Python, and I’m in the process of developing a multi-page web application. One challenge I’ve encountered is the repetition of certain patterns across different pages. I’m wondering if there’s an efficient way to reduce redundancy in my code and streamline the development process.

To illustrate this problem, let’s consider a specific example:

I have an InputGroup containing multiple inputs, such as ‘xmin’, ‘xmax’, ‘delta-x’, and ‘x-step’. These inputs play a crucial role in various callbacks, where they collectively modify a Div. For the sake of simplicity, let’s assume that the content of the Div should be generated as follows: f"[{xmin}, {delta-x}, {xmax}]".

The challenge I’m facing is that I encounter this same problem across multiple pages, each with different datasets. I’m eager to discover if there’s a more efficient approach to tackle both the layout creation and the callback functions.

If anyone has insights or suggestions on how to address this issue effectively, I would greatly appreciate your input.

Thank you in advance for your assistance!

Hi @ulibussi,

I’m not sure if I understand you correctly, but I would store the data in a dcc.Store() in the home page.

1 Like

Sorry if I wasn’t clear. My idea is: I have multiple components (lets say a, b and c) working in diferents pages of a multipage ( P1. P2, P3). Aditional I have some dataset (lets say X,Y,Z, Zx, Zy with sizes n ,m, nxm, n , m ).

1- Some components are shared using the same data between pages ( for example I have component a appears in P1 and P2.
2- Other components (lets say b) must work with X, Zx in a page and Y, Zy in other.

Here “2-” is a common case ( I have similar problem in multiple parts). And the zero order solution is to replicate code and change ids and data between them. I think there must be a “more elegant”, efficient way to solve this
PD: sorry for my english