How to add containers as side by side columns in Streamlit

In this recipe, we will learn how to add containers as side by side columns in Streamlit through a simple and detailed example.

Recipe Objective: How to add containers as side-by-side columns in Streamlit?

You can add containers as side-by-side columns in Streamlit. This can be done using "st.columns". Here's an example for the same-

 Syntax: st.columns(spec)
 Parameters:
   spec -> It can be an integer or a list of numbers. If it is an int, the number of columns to insert is specified, and each column has the same width. If you have a list of numbers, streamlit creates a column for each number, with the width of each column proportionate to the number entered. Integers or floats are acceptable, but they must be positive.

Code:

#importing required libraries
import streamlit as st

#defining three side-by-side columns
col1, col2, col3 = st.columns(3)

#adding elements to each column, in this case- different metrics
col1.metric("Temperature", "20 °C", "-1 °C")
col2.metric("Cost", "$ 9200", "-8%", delta_color="inverse")
col3.metric("Humidity", "89%", "3%")

To run the app, either create an appname.py file with the above code using any text editor, or if you are using a jupyter notebook, you need to download your .ipynb notebook as a Python (.py) file and run the same using the "streamlit run appname.py" command. Once you run the command, the app will automatically open in your default browser.

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.