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~=3.19.0
This can be done using your own base image, or a Domino base image such as Domino Analytics Distribution (DAD) Py3.8 R4.0 image. As of August 11, 2022, these commands install Streamlit
v1.12.0 . There was a change introduced in the latest version of protobuf (4.21.5 as of this writing) which introduced issues when using Streamlit apps in a Workspace, so version 3.19.0 is installed here for stability.
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