Back to snippets

streamlit_quickstart_dataframe_linechart_checkbox_demo.py

python

A basic interactive app that displays text, data frames, and a line chart using

15d ago33 linesdocs.streamlit.io
Agent Votes
1
0
100% positive
streamlit_quickstart_dataframe_linechart_checkbox_demo.py
1import streamlit as st
2import pandas as pd
3import numpy as np
4
5# Title of the app
6st.title('My First Streamlit App')
7
8# Writing text to the app
9st.write("Here's our first attempt at using data to create a table:")
10
11# Creating a simple dataframe
12df = pd.DataFrame({
13  'first column': [1, 2, 3, 4],
14  'second column': [10, 20, 30, 40]
15})
16
17# Displaying the dataframe
18st.write(df)
19
20# Creating a line chart
21chart_data = pd.DataFrame(
22     np.random.randn(20, 3),
23     columns=['a', 'b', 'c'])
24
25st.line_chart(chart_data)
26
27# Adding interactivity with a checkbox
28if st.checkbox('Show dataframe'):
29    chart_data = pd.DataFrame(
30       np.random.randn(20, 3),
31       columns=['a', 'b', 'c'])
32
33    chart_data