#007 - Engineering Dashboards | 01. Solara - The Basics
Exploring Interactive Dashboards in Engineering with Solara: A Beginner's Guide to Python-Driven Data Visualization and Analysis
In today's professional engineering landscape, the integration of technology, especially Python, for data management and calculations, is becoming increasingly recognized. This Flocode series introduces interactive dashboard tools, how to use them and their practical applications in engineering tasks/projects.
Introduction to Dashboard Tools in Engineering
Dashboards serve as dynamic interfaces, enabling engineers and their teams to visualize data, perform calculations, and interact with results in real-time. Tools like Shiny for Python, Gradio, Streamlit, Dash, Voila and Solara, to name just a few, have been turning heads with their approachable out-of-the-box functionality. If you want to see how deep this rabbit hole goes, check out the PyViz list of Python visualization tools.
Despite the multitude of options available, the focus of this post will be on Solara, a tool that stands out for its user-friendly interface, beautiful ready-made components and robust capabilities, making it ideal for engineers using Python.
Why are these tools useful?
These tools can abstract away a large portion of the heavy lifting when it comes to designing a functional user interface at the front end. Anyone who has toyed with web development, JavaScript and state management knows that things can get complicated quickly.
Dashboard frameworks transform complex datasets into easily understandable visual formats. For engineers, this means converting extensive numerical tables into clear, insightful plots. Such visual representations not only aid in quicker comprehension but also assist in making informed decisions, a fundamental role of the professional engineer. Additionally, dashboards democratize the use of advanced calculations, allowing even those with a basic understanding of Python to create powerful analytical tools. They also offer secure, interactive experiences for non-technical users, like clients.
My philosophy leans heavily towards fostering an open and transparent work environment. This approach not only keeps my team agile but also ensures that everyone is constantly aware of the project's status, emerging challenges, and key milestones. If somebody catches an error or a misinterpretation of data/scope, I’ll gladly face the music sooner rather than later.
Throughout this series, we'll explore how these dashboard tools can change the way we deliver our Projects. We will begin with Solara, guiding you through its installation, basic functions, and how to build your first simple engineering dashboard. Should sufficient interest be there, subsequent newsletters will delve into more advanced features and real-world applications in civil and structural engineering. But that’s up to you, so let me know where you want this topic to go.
Solara Overview
Solara is a distinct Python library that stands out in the realm of dashboard tools due to its unique architecture and features. Unlike other dashboard frameworks, Solara is built specifically with Python's async capabilities, allowing for more efficient handling of concurrent tasks and real-time updates. This makes it particularly suitable for engineering applications where real-time data processing and visualization are critical.
Solara integrates with the wider Python ecosystem and works effortlessly with popular data science and engineering libraries like Pandas, NumPy, and Matplotlib, making it a pragmatic tool for engineers who already work with these libraries.
What sets Solara apart, in my opinion, is its reactive programming model. Unlike traditional request-response models used in many web frameworks, Solara's reactive architecture automatically updates the UI when underlying data changes. This means engineers can create highly dynamic and responsive applications where changes in input parameters immediately reflect in the output, crucial for simulations and iterative design processes in engineering.
Furthermore, Solara offers a simple, declarative syntax that reduces the complexity often associated with web application development. This user-friendly approach allows engineers to focus more on the engineering aspects of their projects and less on the intricacies of web programming.
Getting Started with Solara
The best place to start is always, and forever, the official Solara documentation.
You can take a look at some of their excellent examples for inspiration.
Starting with the end in mind, remember that a Solara app offers versatile deployment options for end users:
Web Page: The app can be hosted on a web server, allowing users to access it via a web browser. This is convenient for widespread accessibility.
Local Python Environment: Users can run the app locally in their Python environment. This is ideal for personal use or testing. This is how I use it most frequently.
Containerized in Docker: The app can be containerized using Docker, making it platform-independent and ensuring consistent performance across different systems.
Windows Executable: It's possible to package the app into a Windows executable for users who prefer a traditional desktop application.
This flexibility ensures that Solara apps can be accessed and used in various environments, catering to diverse user needs.
Solara Case Study: A Simple Concrete Calculator
Let’s build an interactive Solara app from the ground up. This simple application serves as an example of how engineering calculations can be integrated into a user-friendly web interface.
Purpose and Functionality
The Concrete Slab Weight Calculator is designed to compute the weight of a concrete slab based on user-inputted dimensions and density. Users enter the length, width, and depth of a slab, along with the concrete's density, and the app calculates the weight in real time.
This simple calculation example demonstrates the ease with which more complex engineering calculations can be automated and visualized.
Development Process
The code for this example can be found on my GitHub. I encourage you to clone the repository and adapt the code to suit your needs or simply play around to test features and understand functionality.
I'll outline the fundamental steps of building such an application, noting that Solara offers a vast array of possibilities and configurations, all thoroughly documented in the official Solara documentation. This is just one instance of what you can achieve with Solara, I plan to share more examples of different functionality in the future.
I won’t dig deeply into the code in this post but if that’s something you are interested in, then let me know! My goal here is to give you a bird’s eye view of the planning and development process so that you can understand the overall scope of such a tool for your specific engineering purposes.
Initial Setup and Installation of Solara:
The process begins with installing Solara, a Python library, using pip. It's essential to set up a suitable Python development environment, preferably with virtual environments, to manage dependencies. This process is described in the example Github respository.
Code Structure and Key Components
This example provides a dynamic web application using Solara, focusing on intuitive layout, interactive elements, and automatic updates. Here's a brief overview:
Layout: Utilized the Solara library methods
solara.Column
andsolara.Card
for a clean, organized UI. This structured approach helps in logically placing components like inputs and displays. Many possibilities are shown in the Solara examples page.Markdown & Sliders: Leveraged
solara.Markdown
for informative text and instructions. Integratedsolara.SliderFloat
to allow users to adjust slab depth, showcasing how sliders can effectively gather user inputs.Input Fields: Implemented
solara.InputFloat
for length and width inputs, ensuring a user-friendly way to enter numerical data.Reactive & Dynamic Functions: The core of the app lies in its reactive state management. Using
solara.use_state
, the app instantly recalculates and updates the slab weight whenever there's a change in inputs. This showcases Solara's ability to create responsive applications where output dynamically adapts to user interaction.
How to Develop Your Own Custom Tool
Building your own interactive engineering tool doesn’t have to be an impossible task. Once you have a clear idea of what you want to do, you’re already well on your way. Here’s a simple roadmap to get you started, and remember that these generalized considerations apply to all dashboard tools, not just Solara.
1. Define the Problem and Objective:
Just as in engineering, clarity at the start is key. Understand specifically what you're trying to solve or automate.
Define the objective of your tool (e.g., automate a certain calculation or visualize specific data in a certain way).
2. Decide on Necessary Inputs:
Determine what inputs are required (dimensions, material properties, coordinates, temperature etc.).
Consider how these inputs are collected (sliders, text fields, dropdowns, buttons).
3. Map Out The Functions:
Identify Core Functions: Just as you would in engineering design, identify the fundamental processes and logic your tool needs to perform. For example, if you're building a load calculation tool, what specific calculations/steps are necessary? How will the inputs be sequenced? Be wary of interdependency.
Simplify Complex Processes: Deconstruct complex tasks into simpler functions. This not only makes your code easier to manage but also easier to debug and maintain.
Modular Approach: Aim for modularity in your functions. Each function should ideally perform one task or calculation. This way, they become reusable components, easily updated and/or reused.
Iterative Development: Start with basic functionality, then gradually add more complex features. This approach allows for testing and refining each function before integrating it into the larger system.
4. Understand State Management
Mastering state management is key in Solara, and it's important to approach it with patience:
Learn About Reactive States: Start by understanding how reactive states in Solara function. These are variables that, when changed, automatically update the parts of your application that depend on them.
Assess Input Effects: Consider the impact of each input on your application. Changing one input can have a cascading effect on other parts, so it’s crucial to map these relationships accurately.
Trial and Error: Experiment with different inputs and observe how your application responds. This practice will give you a clearer understanding of state interactions and their implications.
5. Design with a User-Centric Approach:
Simplicity is Key: Start with a basic, intuitive layout. As you grow more confident in UI design, you can gradually introduce more complexity.
Clear Communication: Use clear, concise labels and instructions. Remember, not everyone using your app may have a technical background.
Focus on User Experience: Regularly step back and view your app from a user's perspective. Ask yourself if every element is self-explanatory and if the workflow is logical and straightforward.
6. Test and Iterate:
Begin Simply: Launch with a minimal viable product. This allows you to ensure the core functionality works well before adding more complex features. Only build what you need.
Gather Feedback: Engage with your end-users - other engineers in your field - to test the app. Their insights are invaluable for making improvements.
Iterative Development: Incorporate the feedback to refine and enhance your application. Continuous improvement is key to developing a tool that is both useful and user-friendly.
Conclusion
Solara offers a gateway for engineers to integrate Python into their workflow, enhancing data visualization and interactive calculations. For those embarking on this journey, resources like the Solara Documentation are invaluable.
Now, it’s your turn. I’m eager to hear from you. Have you used Solara or other dashboard tools in your projects? What unique challenges did it help you overcome? Or, if you’re just getting started, what questions do you have about implementing it in your workflow? Your insights, experiences, and inquiries are invaluable, not just to me, but to our entire engineering community.
If you made it this far, you’re obviously interested in Python, flocode.dev provides tailored learning paths and resources for engineers like you. Our courses delve much more deeply into these topics.
Stay curious and keep exploring – the possibilities with Python and Solara in engineering are vast and ever-growing. I’ll be coming back to this topic soon to dig more into the data visualization aspects of dashboard tools.
See you in the next post!
James🌊