How do you manage large apps? Is there any way to refactor it into functions?

Summary

An app Iā€™m building is getting very big/long. Think 2000+ lines of mostly Streamlit code.

This is because I have some widgets, some graphs, some tabs, columns, metricsā€¦ etc.

I would like to refactor this into smaller files to manage the complexity - but I donā€™t know what is Streamlitā€™s best practice for this.

Maybe my code should look like this:

from helpers import render_widgets, render_data, render_charts, rernder_metrics

filters =  render_widgets()
selected_data = render_data(filters)
charts = render_charts(selected_data, filters)
rernder_metrics(charts, selected_data, filters)

But in this case the render_widgets function (for example) would be generating multiple columns of widgets of various kindsā€¦ etc.

I spend alot of time refactoring. Consider start by using multipage and integrate databases.

Many of my streamlit apps looks somthing like this:

Note: I am a heavy user of the GitHub - victoryhb/streamlit-option-menu library. It helps alot with partitioning my app. Donā€™t like the native multipage method to be honest, so I use an old one: streamlit-multipage Ā· PyPI

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.