Getting started with Streamlit in Domino
Here's how you can do cool things with Streamlit in Domino:
1. Installation: Install these packages in a compute environment in Domino:
RUN pip install streamlit --upgrade RUN pip install protobuf --upgrade
I created a new compute environment by using the Domino Analytics Distribution (DAD) Py3.7 R3.6 image as the base image. These commands installed streamlit
v0.76.0 and protobuf
2. Building a streamlit app: To demonstrate this, I created a simple app file called
streamlit_app.py in my
streamlit-demo project by using the code at https://raw.githubusercontent.com/streamlit/demo-uber-nyc-pickups/master/streamlit_app.py. I ran into an error with
beta_set_page_config on line 25 of the hosted code so ended up just commenting out that line.
3. Live testing the streamlit app: You can leverage jupyter server proxy to host your code as an app from within a jupyter workspace. To do so, ensure that jupyterlab and jupyter server proxy are installed in the compute environment before you launch a jupyterlab workspace. If you are using a DAD environment, this should be already installed for you.
Considering that the streamlit app file
streamlit_app.py is ready for development/testing in my
/mnt directory in my project files, launch a new terminal in jupyterlab and run the streamlit app using the following commands:
streamlit run streamlit_app.py
This will host the app and enable you to access it via jupyter server proxy in a new browser tab by building a URL with the run-id of your workspace:
By default, streamlit apps get published on port
8501. In my case, I grabbed the run-id for my workspace from the URL and built a new URL for live testing the streamlit app as follows:
Note the trailing `/` at the end of the URL. Please specify it in the URL else your app will not load.
4. Publishing the app (once development is done): You can publish this app in Domino with just a bunch of clicks once the app development is complete. To do so, create an
app.sh file in your project and add the following contents inside:
mkdir ~/.streamlit echo "[browser]" > ~/.streamlit/config.toml echo "gatherUsageStats = true" >> ~/.streamlit/config.toml echo "serverAddress = \"0.0.0.0\"" >> ~/.streamlit/config.toml echo "serverPort = 8888" >> ~/.streamlit/config.toml echo "[server]" >> ~/.streamlit/config.toml echo "port = 8888" >> ~/.streamlit/config.toml echo "enableCORS = false" >> ~/.streamlit/config.toml echo "enableXsrfProtection = false" >> ~/.streamlit/config.toml streamlit run streamlit_app.py
The app.sh file tells Domino what to deploy along with the host and port information. After you save the
app.sh file, you can navigate to Publish > App > Follow the form and Start the App.
Once the app is published, you can view your app by clicking the View App button.
You can also view the same app by navigating to https://demo.dominodatalab.com/u/akshay_ambekar/streamlit-demo/app