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


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