evolving Streamlit in Snowflake: Race to the Finish Line with your Native App in Snowflake

evolv Consulting
6 min readMar 8, 2024

--

Part 3, by Chris Schneider

Thank you for continuing on our journey to part three of our three-part series on taking your custom Snowflake Native App in Streamlit to the next level. Drawing inspiration from real-life problem-solving explorations at our evolv Hackathon, this chapter of “evolving Streamlit in Snowflake” unveils how we significantly enhanced user experience by reducing wait times for new requirements. We achieved this by leveraging a data-driven framework to minimize development effort and effortlessly expand our dashboard with speed and efficiency. Whether you are a beginner or an expert in Streamlit, these techniques will elevate your app across the finish line in record time. 🏁

What is Streamlit?

In case you missed the first two parts of our series, Streamlit is an approachable open-source Python library that enables you to quickly build simple and robust data-centric applications. The impact of Streamlit on data app development and dissemination has been groundbreaking. Its user-friendly interface, rapid performance, and vibrant community have truly revolutionized the landscape for data professionals.

For those new to Streamlit, here’s a quick-start guide that will help you install and run your first app.

Hurry up and Wait!

User experience (UX) is a pivotal competitive factor that helps determine whether your audience continues to use your product or moves on to the next shiny, new object. It’s not just about what’s visible in the app or its navigational ease…User experience expands to overall experience of the application, including ability to grow and evolve as user’s questions/needs change over time.

Imagine that each time a user came up with a new measurement to report on, they had to wait days or even weeks for an SDLC to run the requirement through its paces before being able to see the metric in their dashboard.

We recently encountered a scenario where we wanted to display a set of KPIs on various subjects while providing the user audience the ability to adjust filtering through a range of days/hours. Our initial attempts proved useful for the audience. The users had metrics that were important and flexibility to filter to meet their high-level questions. As users began to use the tool, they wanted more… fast. We started to get feedback… “Can you add a metric for total Sales in the Midwest Region over the last quarter?” or “It would be awesome if I could see how much we spent on supplies last month!”

Carefully Considered Plans!

Streamlining the SDLC process to quickly adapt applications to evolving requirements is a significant step in the right direction. This could involve many team members across many functions within an organization, or or have minimal impact on just a single team… While this improvement absolutely is beneficial, sometimes people and process need a *bit* more help from their ally, technology. #worksmarternotharder

We tackled the technical aspects of improving speed-to-market in our application by implementing a data-driven strategy to incorporate metrics into our dashboard. This strategy consists of a set of data stored directly within the application database and also leverages some more complex components within Streamlit and Python to get to the finish line.

· Caching: Taking advantage of caching in Streamlit enables the reuse of each query for additional metrics and reduces user wait time for screen refreshes when modifying filter options.

· Threading: Each metric is processed on a separate thread, allowing asychronous retrieval of the metric data sets and aggregate calculations. Then as each dataset is returned, Streamlit begins placing the metrics on the screen within a configurable number of columns across the page.

The overall process is simple but effective. Start with retrieving the meta data from the application database, processing the meta data; in turn run the metric’s queries while caching the results for later use and user interaction. Then concluding with a display of metrics for the user to consume.

This framework is managed by a simple data model consisting of 3 tables and a view:

· Metric — Sets the base configuration of a metric, covering type, output format, labels, and help text for display purposes. Notably, each metric includes a trend automatically derived from the selected slider value and existing data queries.

§ Note — each metric also contains a trend which is automatically calculated based on the selected slider value and the existing data queries

· Query — a list of queries that can be mapped to Metrics to be used to retreive the data for each metric. Each query follows a simple data contract and provides:

Value — the sum of items specified or filtered from the source for an historical day

History- the date of occurrence represented simply as the integer number of the days from today in history

· Metric_Query — an association of Metrics to their Query or Queries if more than 1 query should be used, for Rate calculations.

· Metric_All_Active — a view that returns only active metrics and all corresponding configuration and query data.

Currently 2 types of metrics are easily supported:

1. Sum — provides a single output summary (aggregate count or sum) of items by day. Example: Count of all Items per Day or Count of Successful Items per Day.

2. Rate — provides the output of a simple equation (numerator / denominator) to generate rates or averages by day. Example: Success Rate = Count of Successful Items per Day / Count of all Items per Day.

Using this framework, a bit of collaboration with the team, a few lines of SQL, and in just a matter of minutes, we can go from a blank slate…

To a world of metrics, metrics, and even more metrics….

If you are interested in more information about the technical bits and pieces of this solution, including access to the sample code, data tables, and sample data, you can access the full project repository on GitHub at: https://github.com/evolvconsulting/race-to-the-finish-line

Speed Matters

In today’s world of instant gratification, it is imperative that we look beyond the tangible and expand the horizon of possibilities by moving forward swiftly with purpose. Adding those simple, but extremely important, new features to your application quickly can stave off the appetite your audience has for constant improvement. Thus, making your application, the shiny new object your users continuously go to.

I Bid You Adieu, but not for Long!

This is only one of many ways to hit the ground running, and race your Native App across the finish line. Thank you for coming along with me on this journey within Streamlit and Snowflake Native Apps. It has been a pleasure to show techniques from beginner to advanced. Along the way explaining ways of improving the user experience with simple, clever, and outside-of-the-“app” solutions to keep your users engaged. Be sure to check out this entire series if you missed it. Keep experimenting, innovating, and sharing to keep our community vibrant!

If you are interested in how evolv can help you shape the future of Data, visit our blog, and check out some of our previous featured pieces. Feel free to drop your comments below and be a part of the conversation that is shaping the future of data apps.

evolv is a cloud-native consulting firm who brings a fresh perspective to help clients overcome #management and #technology challenges. We specialize in strategy, data & analytics, and digital transformations. Learn more at www.evolvconsulting.com.

--

--

evolv Consulting

We are cloud-native, business consultants who bring a fresh perspective to help clients overcome #management and #technology challenges.