Recently i had a need to assess streamlit for some internal DS/ML/Data apps i wanted to build in my job. By “i had a need” i mean i heard it was the new cool thing so i wanted to play with it and feel better about myself. Anyway, as part of that i built a horribly useless app to try capture the main things i was after.
In the end i went with Dash instead (mainly due to needing tabs and some additional messy ‘state’ related stuff i could find lots of dash examples for) but i’m pretty sure next time i need to do something similar i will 100% use streamlit as my goto given its just so easy to get going with and should be more than acceptable for 80-90% of my use cases (plus its got a lot of momentum and is getting better and better over time).
So in this post i am sharing a little cleaned up version of the dummy streamlit app i built as a little poc to see if i could get what i needed from it. Also, a few student’s in the course where i mentor have been playing with streamlit as part of building an app to share and publish their ml models so i’m hoping this might be useful to refer them too as a potential starting point (although there are many many much cleaner examples in the streamlit gallery). But if you want some of the features below then my little frankenstein here might be an ok starting point for you.
- Some notion of a multipage app where each app can have itself different “screens” or “pages”.
srctype folder where you might write custom python modules you want to have available to all your “apps” or “screens” within the app.
- Ability to easily deploy it to streamlit sharing, for example this app should be up and available here.
- Show different logos etc on different pages.
- Have dynamic inputs that can vary in types and number of inputs depending on each page.
- Some functions to do stuff with the inputs.
TL; DR – Here is the app running on streamlit share: https://share.streamlit.io/andrewm4894/streamlit-learn/main/app.py and here is the code on Github.
Here is how the project is structured and below are some notes on each folder or file.
Here are each of the main folders/files and what they do.
/.streamlit– This is where some streamlit specific config files like
config.tomllive, more info in streamlit docs here.
/apps– This is where we have an
app_<name>.pyfile for each app within our overall streamlit app. For example,
/apps/app_silly_strings.pycontains as much of the logic and code that is specific to the “silly string stuff” app.
/assets– The place where your images and other similar types of files live that you want to use across your apps.
/src– For python code and functions you want to have available on any page of your app you can make a custom module in here. For example the
funny_numbersmodule has the functions used by the “crazy numbers” app.
app.py– This is the main streamlit app we launch via
streamlit run app.pywhich will import and render the other apps as needed.
Pipfile– Pipenv is used in this example instead of a requirements.txt or any other approaches to define the python environment the app should run in.
That’s it, you can look at the code and see it all for yourself, i’ve also added a README to each folder to make it as clear as possible (some potential todo’s that could make it a better example).
Lastly, here is a pointless video of me clicking some stuff…