I’ve got a working streamlit app that I wanted to clean up a bit by reorganizing the code into modules and I decided to review the source code for the
streamlit hello app to get a sense of best practices.
I was surprised to see that the app runs the necessary imports for each demo app inside of the corresponding function for that app. For example:
def mapping_demo(): import streamlit as st import pandas as pd import pydeck as pdk @st.cache def from_data_file(filename): url = ( "https://raw.githubusercontent.com/streamlit/" "example-data/master/hello/v1/%s" % filename) return pd.read_json(url) ...
Is that a recommended practice for Streamlit or something specific to the demo? Is it a more general practice that I’m just unaware of (as opposed to doing all imports at the top of each file)?