Streamlit and Plotly Tutorial
1. Installation(For Windows, Mac is easier and similar to this)
Install plotly, pandas and numpy also through pip Run below code in cmd or console: pip install plotly pip install pandas pip install numpy
Copyright By PowCoder代写 加微信 powcoder
2. How to run streamlit file(Result is a pop up local website) Create a py file called app.py
In the py file, write below code:
import streamlit as st st.write(“Hello World!”)
If the installation is correct, run the py file should pop up some suggestion not errors.
In Anaconda Console, run:
python app.py
Remember to switch to the folder containing app.py file in console
If above works, try running:
streamlit run app.py
If everything’s correct, a local webpage should be pop up with “Hello World!”.
3. Load Data File and Plot Charts using plotly and streamlit Below is the link to Tutorial Example: http://github.com/DaG0ng/EsportPlayer-Web-Page
First run test.py in the folder for first step tutorial
import pandas as pd import streamlit as st import plotly.express as px import plotly.graph_objects as go
from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures import numpy as np
# Print the title st.title(“Streamlit Tutorial”)
# Print a line of text st.write(“Hello World!”)
# Load some data in csv and show them df = pd.read_csv(“data/line-chart-data.csv”) st.write(df)
# Use plotly to display the line chart of dataframe we loaded # Create a streamlit selectbox which can narrow down certain data we need game = [‘All’] game += list(df[‘Name’].unique()) values = st.selectbox(“Select Game”,game)
if values != ‘All’:
selected_df = df.where(df[‘Name’]==values) selected_df = selected_df.dropna()
selected_df = df selected_df = selected_df.dropna()
# Now create the chart using plotly f = px.line(selected_df, x=”Year”, y=”Tournaments#”,title=’Tournament per Year’,color=’Name’)
# Use streamlit to show the plotly chart object n st.plotly_chart(f)
After execution run the code below in console:
streamlit run test.py
Don’t close the pop up webpage and edit something in the py file like change
st.title(“Streamlit Tutorial”)
st.title(“Change for fun”)
You’ll see a few buttons in the upper-right corner of the webpage asking if you’d like to rerun the app. Choose Always rerun, and you’ll see your changes automatically each time you save.
In this way, you can have the live view of the webpage you are working on.
4. Plot charts using plotly and streamlit Check the app.py
5. References
Streamlit Tutorial: https://docs.streamlit.io/library/get-started Plotly Express Tutorial: https://plotly.com/python/plotly-express/ Link to the example page:
https://github.com/DaG0ng/EsportPlayer-Web-Page
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com