-
Notifications
You must be signed in to change notification settings - Fork 0
/
25. Interactive Data Visualization.py
154 lines (118 loc) · 4.05 KB
/
25. Interactive Data Visualization.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import datetime
import streamlit as st
# st.title('My First App')
# st.header('This is Button')
# if st.button('click me!'):
# st.write('Clicked!')
# else:
# st.write('Click the Button!')
# st.header('This is checkbox')
# if st.checkbox('Hello, Click me!'):
# st.write('Checked!')
# else:
# st.write('Unchecked')
# st.header('Radio Button')
# selected_radio = st.radio('What is your favourite Genre',
# ['Comedy', 'Romance', 'Action'])
# if selected_radio == 'Comedy':
# st.write('Good Choice!')
# elif selected_radio == 'Romance':
# st.write('Sweet!')
# else:
# st.write('Bravo!')
# st.header('This select box')
# selected_box = st.selectbox('What is your favourite Genre',
# ['Comedy', 'Romance', 'Action'],
# index=1)
# if selected_box == 'Comedy':
# st.write('Good Choice!')
# elif selected_box == 'Romance':
# st.write('Sweet!')
# else:
# st.write('Bravo!')
# st.header('This is Multi-Select box')
# output_multi = st.multiselect('Your favourite colour?',
# ['Green', 'Yellow', 'Blue', 'Red'],
# ['Green', 'Blue'])
# st.write(type(output_multi))
# st.header('this is slider')
# slide = st.slider('Select Range of Values', 0, 20, [5, 10])
# st.write(slide)
# st.header('this is range select')
# slide = st.select_slider('Select fruits', ['Apple', 'Mango', 'Strawberry', 'Orange', 'Kiwi'],
# ['Apple', 'Strawberry'])
# st.write(slide)
# st.header('This date')
# st.date_input('Input date')
# st.header('This time')
# st.time_input('Set alarm', datetime.time(8, 30))
# st.sidebar.title('This is sidebar')
# st.sidebar.selectbox('select pages', ['page 1', 'page 2', 'page 3'])
# st.sidebar.caption('demo only')
# arr = np.random.normal(1,1, size=50)
# arr
# st.subheader('Matplotlib')
# fig, ax = plt.subplots()
# ax.hist(arr)
# st.pyplot(fig)
# st.subheader('seaborn')
# fig2, ax2 = plt.subplots()
# sns.histplot(arr, ax = ax2)
# st.plotly_chart(fig2)
# st.subheader('plotly')
# df = px.data.gapminder().query("country=='Canada'")
# fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
# st.plotly_chart(fig)
# @st.cache
# def load_data():
# data = pd.read_csv('Pokemon.csv')
# return data
# df = load_data()
# st.write(df)
# fig, ax = plt.subplots()
# sns.histplot(df['Attack'], ax=ax)
# st.pyplot(fig)
# # kombinasi dengan widget interactivity
# selected = st.selectbox('Select Type 1', list(df['Type 1'].unique()))
# fig1, ax1 = plt.subplots()
# sns.histplot(df[df['Type 1'] == selected]['Attack'], ax=ax1)
# st.pyplot(fig1)
# selected_2 = st.radio('Select Generation', [1, 2, 3, 4, 5, 6])
# fig2, ax2 = plt.subplots()
# sns.scatterplot(df[df['Generation']==selected_2]['Attack'], df[df['Generation']==selected_2]['Speed'], ax=ax2)
# st.pyplot(fig2)
import streamlit as st
import pandas as pd
import numpy as np
st.title('Uber pickups in NYC')
DATE_COLUMN = 'date/time'
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
'streamlit-demo-data/uber-raw-data-sep14.csv.gz')
@st.cache
def load_data(nrows):
data = pd.read_csv(DATA_URL, nrows=nrows)
lowercase = lambda x: str(x).lower()
data.rename(lowercase, axis='columns', inplace=True)
data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
return data
data_load_state = st.text('Loading data...')
data = load_data(10000)
data_load_state.text("Done! (using st.cache)")
if st.checkbox('Show raw data'):
st.subheader('Raw data')
st.write(data)
st.subheader('Number of pickups by hour')
hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
st.write(hist_values)
st.bar_chart(hist_values)
# Some number in the range 0-23
hour_to_filter = st.slider('hour', 0, 23, 17)
filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]
st.write(filtered_data)
st.subheader('Map of all pickups at %s:00' % hour_to_filter)
st.map(filtered_data)