plotly express in streamlit

Solutions on MaxInterview for plotly express in streamlit by the best coders in the world

showing results for - "plotly express in streamlit"
Rose
14 Jan 2017
1import streamlit as st
2import pandas as pd
3import plotly.express as px
4
5
6@st.cache()
7def load_data():
8    df = pd.read_csv(
9        'https://github.com/chris1610/pbpython/blob/master/data/cereal_data.csv?raw=True'
10    )
11    return df
12
13
14# Read in the cereal data
15df = load_data()
16
17st.title('Rating exploration')
18
19# Only a subset of options make sense
20x_options = [
21    'calories', 'protein', 'fat', 'sodium', 'fiber', 'carbo', 'sugars',
22    'potass'
23]
24
25# Allow use to choose
26x_axis = st.sidebar.selectbox('Which value do you want to explore?', x_options)
27
28# plot the value
29fig = px.scatter(df,
30                x=x_axis,
31                y='rating',
32                hover_name='name',
33                title=f'Cereal ratings vs. {x_axis}')
34
35st.plotly_chart(fig)
36