Streamlit in Snowflake Applications
1. Streamlit in Snowflake Applications
Streamlit is a powerful open-source Python library for building data apps in pure Python. No HTML, CSS, or any other fancy web technologies or frameworks needed. Apps built with Streamlit are incredibly easy to deploy and share. This makes Streamlit a great way of sharing and delivering your data products. To top things off, Streamlit is natively available within Snowflake, known as Streamlit in Snowflake. This makes it even easier for you to build and share Streamlit applications directly in your Snowflake account. And you're not limited to visualizing data in the Streamlit app. Using Streamlit components, you can build custom user interfaces and build complex data and AI applications. You can do things like capture user input in the form of dropdowns, text inputs, and radio buttons. You can bring in open-source packages and use them in the application. You can even build RAG-based chatbots that allow you to talk to your data in natural language. This only scratches the surface of what's possible, and I encourage you to check out the Streamlit documentation for more inspiration. Let's build and share a Streamlit in Snowflake app that visualizes the weather Hamburg view that we created earlier. It's a good time to pause the video to make sure you're logged into your Snowflake account. Navigate to Projects and click on Streamlit. Click the button to create a new Streamlit app. Name your Streamlit app and choose a database and schema where the app will live. I'm going to select Tasty Bytes and Harmonized. I'll also select the Compute Warehouse virtual warehouse to associate with the app. Click Create. You'll see the application boot up, and it will display a sample application. Let's take a look around. On the left, you'll have your Snowflake object picker, where you can see all of the databases, apps, and other things. In the middle, you have a full-fledged Python editor, where you can write the code that powers your app, and on the right, you see a real-time rendering of the current state of the application. If you make edits to the sample app that loads, you can click on Run at the top, and the application will instantly re-render to reflect the most current state, assuming there are no errors. This setup makes it incredibly easy to edit and quickly preview changes in your application. And again, I'm entirely within Snowflake. This isn't a Python course or a Streamlit course, so we won't walk through code or syntax line by line. Instead, focus on the high-level moving parts and what we're building, then you can dive deeper into specific parts of the process you might have questions about. Let's build our app. Navigate to the StreamlitWeatherHamburg.py file in the Streamlit in Snowflake folder within the Module 4 folder. Copy the code. Remove all of the current Python code in the code editor in Snowflake, and paste in the code that you copied from our Python file. Let's take a look at what's going on. At the top, you can see I'm importing the relevant packages, and if I wanted to use more packages, I could use the package picker here at the top to install them and then just bring them into my code. At the top, I start a Snowpark session using `get_active_session()`. Then, I use st.title to write some text to the app. Then, I load my DataFrame, which is based on the WeatherHamburg view in my account. I'm going to cast my DataFrame to a pandas DataFrame using `to_pandas()`. And then, I'll create a chart here to render the data. First, I define my desired legend titles. Then, I start creating my chart by passing in the DataFrame to the chart object. There are some other properties that I configure for the chart below this as well. Click Run. And now, you'll see I have an application that uses the transformed data in my account to deliver an insight. If I want to share it, I can click on Share at the top right, where you'll see I can share the app with more roles in my account, and I can also grab a handy link to the app as well. The neat thing, this app is only about 54 lines of code. In 54 lines of code, we built a Streamlit in Snowflake app that delivers insights to teammates, and all within the same Snowflake account. It was super easy to create and share, and no data ever left my account. Let's quickly recap what you learned. You learned that Streamlit is natively available within Snowflake, known as Streamlit in Snowflake. You learned that you can build data apps using just Python, all within your account. And you learned that you can easily share these apps with users in your account. Coming up, we'll go beyond sharing apps in your Snowflake account to sharing data apps with users in the entire data cloud.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.