Adventures in Machine Learning

Mastering Theming in Streamlit: GUI & Code Method Explained

Introduction to Theming in Streamlit

Streamlit is a powerful and easy-to-use web application framework for Python. One of the many advantages of Streamlit is its ability to change the theme of the app.

Changing the app’s theme is an important aspect of user interface design, as it helps to improve the user experience and provides users with options to customize the app according to their preferences. In this article, we will explore the different ways of changing the theme in Streamlit.

We will cover the default themes and user preferences, as well as the two methods for changing the app theme – GUI and Code method. Whether you are a beginner or an advanced user, this article aims to provide you with a comprehensive understanding of theming in Streamlit.

Default Themes and User Preferences

Streamlit offers a range of default themes that allow users to choose from a variety of pre-built color palettes. These themes can be accessed by adding the following line of code to the Streamlit app:

“`

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”)

“`

You can find a list of the available theme options on the Streamlit documentation page.

Additionally, users can customize the app’s theme by entering their preferred color codes or selecting a custom background image. To achieve this, users need to use the “set_page_config()“ function and pass in their preferred color or image URL as argument(s).

Changing the Theme through GUI

The Graphical User Interface method (GUI) is the easiest and most straightforward method for changing the theme in Streamlit. To do this, navigate to the Streamlit app’s top right corner and click on the `Settings` button.

From there, you would see the `Themes` dropdown menu, which contains all available themes. Simply click on the preferred theme, and the app’s entire theme color scheme will change.

Changing the Theme through Code

While the GUI method is easy, it is not always the best method for changing a Streamlit app’s theme. For instance, if you want to change the theme dynamically at runtime, or you want to specify a custom color for a specific widget, the code method is the best option.

To change the theme through code, you use the `set_page_config()` function and specify the theme you want. The function takes in four optional parameters:

– “page_title“: The title of the app page (default value is “Streamlit App”).

– “page_icon“: The page icon that appears on your browser tab (default value is blank). – “initial_sidebar_state“: The initial state of the app sidebar (options are “auto”, “expanded”, or “collapsed”).

– “theme“: The theme of the app, which can either be specified as a dictionary, or by passing in a string with the options listed below. The following are the different options for the “theme“ parameter:

– “Default“

– “Light“

– “Dark“

– “Purple“

– “Green“

– “Blue“

– “Orange“

– “Red“

Here is an example to set the app theme to “Blue“ using the code method:

“`

import streamlit as st

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”, theme=”Blue”)

# Your Streamlit app code here.

“`

Methods for Changing Streamlit App Themes

There are two ways to change the Streamlit app theme – the GUI method and the code method. Here is a breakdown of each method:

GUI Method

The GUI method is the easiest and most straightforward way to change the Streamlit app theme. Follow these simple steps to use the GUI method:

– Navigate to the Streamlit app’s top right-hand corner.

– Click on the settings button. – In the dropdown menu, select the preferred theme.

Code Method

The code method, on the other hand, requires users to specify the app’s theme programmatically. Here is how to use the code method:

– Import the `streamlit` module.

– Use the `set_page_config()` function to set the app’s theme. – Specify the theme either as a dictionary, or by passing a string with the theme name.

Conclusion

Themining in Streamlit is an important aspect of user interface design that allows users to customize the app to their preferences. While Streamlit offers a range of default themes that users can choose from, the app’s theme can also be changed using the GUI or code method.

These methods provide users with the flexibility to customize their app themes according to their preferences. We hope this article has provided you with the knowledge you need to create visually appealing and stunning Streamlit apps.

Exploring Theme Options in Streamlit

Customizing an app’s theme in Streamlit involves changing the primary color, background color, secondary background color, text color, and font. In this section, we will explore all the theme options in detail, providing you with a comprehensive understanding of how to customize your Streamlit app’s theme.

PrimaryColor

The primary color is the color that dominates the app’s overall theme, typically seen on buttons, links, and other interactive elements. The primary color in Streamlit can be set by specifying the primary color in the configuration function.

By default, Streamlit uses the blue color scheme as the primary color, but users can specify their preferred primary color using HEX color codes. For example:

“`

import streamlit as st

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”, primaryColor=”#FFC300″)

“`

Above, we set the primary color of a Streamlit app to “#FFC300”, which is a golden-yellow color. You can experiment with your desired HEX color code to use in the configuration function.

BackgroundColor

The background color is the color that appears behind the content of the Streamlit app. You can set the background color using HEX codes using the color picker in the settings menu or through the following code:

“`

import streamlit as st

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”, backgroundColor=”#FFFFFF”)

“`

Above, we set the background color of the Streamlit app to white color. Alternatively, users can also use color names to set the background color.

For instance, `backgroundColor=”white”` sets your app’s background to white. Experiment with the available options and pick the one that suits your app’s design best.

Secondary

BackgroundColor

The secondary background color is a secondary color that is usually complementary to the primary color. The complementary color is usually used to highlight some aspects of the app’s design, such as borders and titles.

Here is how to set the secondary background color using HEX codes or color names:

“`

import streamlit as st

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”, secondary

BackgroundColor=”#F1F4FF”)

“`

Above, we set the secondary background color of the Streamlit app to a light-blue color. You can input your desired HEX or color name as preferred.

TextColor

The text color is the color used to display text in a Streamlit app. You can set it using the configuration function using color codes or color names, as shown below:

“`

import streamlit as st

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”, textColor=”#333333″)

“`

Above, we set the text color of the Streamlit app to a dark-gray color. You can experiment with different color codes and find the one that works best for your app design.

Font

You can customize the font of your Streamlit app to improve readability and fit the app style. The default font in Streamlit is Open Sans, but you can also choose from other available options.

Here is an example of changing the font using the configuration function:

“`

import streamlit as st

st.set_page_config(page_title=”My Streamlit App”, page_icon=”:smiley:”, layout=”wide”, font=”serif”)

“`

Above, we set the font of the Streamlit app to a serif font. Experiment with different font options to find the one that works best for your app design.

Conclusion

In this article, we have explored all the different ways of customizing your Streamlit app’s theme. We have covered primary color, background color, secondary background color, text color, and font.

By understanding these theme options, you can customize your Streamlit app to suit your unique needs. We hope that this article has provided you with valuable insights on how to improve your Streamlit app’s design and user experience.

In this article, we have explored theming in Streamlit, a powerful and easy-to-use web application framework for Python. We have covered the default themes and user preferences, as well as the two methods for changing the app theme- GUI and code method.

We’ve also delved into how to explore theme options in Streamlit, such as primary color, background color, secondary background color, text color, and font. By understanding these different streams, developers can customize their Streamlit app according to their preference and enhance its overall user experience.

We hope that this article has provided valuable insights into designing and customizing a Streamlit app’s theme.

Popular Posts