-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdata_visualization_app.py
More file actions
92 lines (80 loc) · 3.09 KB
/
data_visualization_app.py
File metadata and controls
92 lines (80 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st
import plotly_express as px
import pandas as pd
# configuration
st.set_option('deprecation.showfileUploaderEncoding', False)
# title of the app
st.title("Data Visualization App")
# Add a sidebar
st.sidebar.subheader("Visualization Settings")
# Setup file upload
uploaded_file = st.sidebar.file_uploader(
label="Upload your CSV or Excel file. (200MB max)",
type=['csv', 'xlsx'])
global df
if uploaded_file is not None:
print(uploaded_file)
print("hello")
try:
df = pd.read_csv(uploaded_file)
except Exception as e:
print(e)
df = pd.read_excel(uploaded_file)
global numeric_columns
global non_numeric_columns
try:
st.write(df)
numeric_columns = list(df.select_dtypes(['float', 'int']).columns)
non_numeric_columns = list(df.select_dtypes(['object']).columns)
non_numeric_columns.append(None)
print(non_numeric_columns)
except Exception as e:
print(e)
st.write("Please upload file to the application.")
# add a select widget to the side bar
chart_select = st.sidebar.selectbox(
label="Select the chart type",
options=['Scatterplots', 'Lineplots', 'Histogram', 'Boxplot']
)
if chart_select == 'Scatterplots':
st.sidebar.subheader("Scatterplot Settings")
try:
x_values = st.sidebar.selectbox('X axis', options=numeric_columns)
y_values = st.sidebar.selectbox('Y axis', options=numeric_columns)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.scatter(data_frame=df, x=x_values, y=y_values, color=color_value)
# display the chart
st.plotly_chart(plot)
except Exception as e:
print(e)
if chart_select == 'Lineplots':
st.sidebar.subheader("Line Plot Settings")
try:
x_values = st.sidebar.selectbox('X axis', options=numeric_columns)
y_values = st.sidebar.selectbox('Y axis', options=numeric_columns)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.line(data_frame=df, x=x_values, y=y_values, color=color_value)
st.plotly_chart(plot)
except Exception as e:
print(e)
if chart_select == 'Histogram':
st.sidebar.subheader("Histogram Settings")
try:
x = st.sidebar.selectbox('Feature', options=numeric_columns)
bin_size = st.sidebar.slider("Number of Bins", min_value=10,
max_value=100, value=40)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.histogram(x=x, data_frame=df, color=color_value)
st.plotly_chart(plot)
except Exception as e:
print(e)
if chart_select == 'Boxplot':
st.sidebar.subheader("Boxplot Settings")
try:
y = st.sidebar.selectbox("Y axis", options=numeric_columns)
x = st.sidebar.selectbox("X axis", options=non_numeric_columns)
color_value = st.sidebar.selectbox("Color", options=non_numeric_columns)
plot = px.box(data_frame=df, y=y, x=x, color=color_value)
st.plotly_chart(plot)
except Exception as e:
print(e)