How do I refactor magic to multiple files as the app grows?

Hi Streamlit

Streamlit is truly awesome.

One thing I have not figured out is how to split my app into multiple files as it grows with all files using Magic. How can I do this?

I would like to split my app into a structure like

.
└── src
    β”œβ”€β”€ app.py
    └── pages
            β”œβ”€β”€ page1.py
            └── page2.py

and then in app.py insert contents from page1 and page2 something like

st.insert('pages/page1.py')

Of course I can import functions to app.py from page1 and page2 and then run them on a line. I can also import the page1, page2 modules and add them to a line.

But I wan’t to be able to use all the magic in page1 and page2 as well. It’s magic like β€œβ€β€œThis is Markdown Magic in page1.py”"" I wan’t to work.

I’ve created a feature request here https://github.com/streamlit/streamlit/issues/288

Thanks

3 Likes

@Marc: Thank you for submitting that feature request! :heart: :heart:

Unfortunately, your use case is not supported yet, but I agree. This would be great!

As I’m sure you know, a β€œmagic” statement like:

"The answer is", 42

is just syntactic sugar for

st.write("The answer is", 42)

Therefore, the workaround it to use the slightly less magical st.write syntax. :confused:

I really appreciate the feature request, and I can’t help pointing out that we would be delighted by code contributions as well! :slight_smile:

Btw, it sounds like you’re making something ambitious! Please do share your experience building a multi-file project in Streamlit with the community. I will be very excited to learn more from your experience.

2 Likes

Yes. I’ve shared a link to my multi-page app here Awesome-streamlit resources and gallery. If you have comments or questions feel free to reach out here or at datamodelsanalytics.com.

Marc

1 Like