File size: 8,221 Bytes
b9ebe8b
 
 
 
1152399
 
b9ebe8b
 
9421b07
 
 
 
 
155bad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f72314e
 
 
 
 
 
 
 
 
 
 
 
 
9421b07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3216ee8
 
9421b07
4ab5104
e9a76ab
 
3216ee8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ab5104
 
34d9eb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09fad03
 
 
 
 
 
 
 
 
 
b9ebe8b
2970f7f
4ab5104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2970f7f
 
 
 
4ab5104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9ebe8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f72314e
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import streamlit as st
import numpy as np
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go

st.set_page_config(page_title="Plotly Graphing Libraries",layout='wide')

uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=True)
for uploaded_file in uploaded_files:
    bytes_data = uploaded_file.read()
    st.write("filename:", uploaded_file.name)
    st.write(bytes_data)
    
    if st.checkbox("FileDetails"):

        filevalue = uploaded_file.getvalue()
        st.write(filevalue)
        st.write(uploaded_file.name)
        st.write(uploaded_file.type)
        st.write(uploaded_file.size)
        #st.write(uploaded_file.last_modified)
        #st.write(uploaded_file.charset)
        st.write(uploaded_file.getbuffer())
        st.write(uploaded_file.getbuffer().nbytes)
        st.write(uploaded_file.getbuffer().tobytes())
        st.write(uploaded_file.getbuffer().tolist())
        st.write(uploaded_file.getbuffer().itemsize)
        st.write(uploaded_file.getbuffer().ndim)
        st.write(uploaded_file.getbuffer().shape)
        st.write(uploaded_file.getbuffer().strides)
        st.write(uploaded_file.getbuffer().suboffsets)
        st.write(uploaded_file.getbuffer().readonly)
        st.write(uploaded_file.getbuffer().c_contiguous)
        st.write(uploaded_file.getbuffer().f_contiguous)
        st.write(uploaded_file.getbuffer().contiguous)
        st.write(uploaded_file.getbuffer().itemsize)
        st.write(uploaded_file.getbuffer().nbytes)
        st.write(uploaded_file.getbuffer().ndim)
        st.write(uploaded_file.getbuffer().shape)
        st.write(uploaded_file.getbuffer().strides)
        st.write(uploaded_file.getbuffer().suboffsets)
        st.write(uploaded_file.getbuffer().readonly)
        st.write(uploaded_file.getbuffer().c_contiguous)
        st.write(uploaded_file.getbuffer().f_contiguous)
        st.write(uploaded_file.getbuffer().contiguous)
        st.write(uploaded_file.getbuffer().itemsize)
        st.write(uploaded_file.getbuffer().nbytes)
        st.write(uploaded_file.getbuffer().ndim)
        st.write(uploaded_file.getbuffer().shape)
        st.write(uploaded_file.getbuffer().strides)
        st.write(uploaded_file.getbuffer().suboffsets)
        st.write(uploaded_file.getbuffer().readonly)
        st.write(uploaded_file.getbuffer().c_contiguous)
        st.write(uploaded_file.getbuffer().f_contiguous)
        myDF = pd.DataFrame(uploaded_file.getbuffer().tolist())
        

        st.markdown("# Treemaps from upload data file: https://plotly.com/python/treemaps/")
        #df = myDF.query("year == 2007")
        df = myDF
        fig = px.treemap(df, path=[px.Constant("time"), 'message', 'name'], values='content',
                        color='lifeExp', hover_data=['iso_alpha'],
                        color_continuous_scale='RdBu',
                        color_continuous_midpoint=np.average(df['name'], weights=df['content']))  # todo - debug this and get it working with the data
        fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
        #fig.show()
        st.plotly_chart(fig, use_container_width=True)
   
#show replace     
    if st.checkbox("replace"):
        mydf = st.dataframe(df)
        columns = st.selectbox("Select  column", df.columns)
        old_values = st.multiselect("Current Values",list(df[columns].unique()),list(df[columns].unique()))
        with st.form(key='my_form'):
            col1,col2 = st.beta_columns(2)
            st_input = st.number_input if is_numeric_dtype(df[columns]) else st.text_input
        with col1:
            old_val = st_input("old value")
        with col2:
            new_val = st_input("new value")
            if st.form_submit_button("Replace"):
                df[columns]=df[columns].replace(old_val,new_val)
                st.success("{} replace with {} successfully ".format(old_val,new_val))
                excel = df.to_excel(r"book2.xlsx", index = False, header=True,encoding="utf-8")
                df =pd.read_excel(r"book2.xlsx")       
                mydf.add_rows(df)    

#st.markdown("WebGL Rendering with 1,000,000 Points")

N = 1000000
fig = go.Figure()
fig.add_trace(
    go.Scattergl(
        x = np.random.randn(N),
        y = np.random.randn(N),
        mode = 'markers',
        marker = dict(
            line = dict(
                width = 1,
                color = 'DarkSlateGrey')
        )
    )
)
fig.show()
st.plotly_chart(fig, use_container_width=True)



st.markdown("# WebGL Graph - ScatterGL")
fig = go.Figure()
trace_num = 10
point_num = 5000
for i in range(trace_num):
    fig.add_trace(
        go.Scattergl(
                x = np.linspace(0, 1, point_num),
                y = np.random.randn(point_num)+(i*5)
        )
    )
fig.update_layout(showlegend=False)
#fig.show()
st.plotly_chart(fig, use_container_width=True)


st.markdown("# Treemaps: https://plotly.com/python/treemaps/")
df = px.data.gapminder().query("year == 2007")
fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',
                  color='lifeExp', hover_data=['iso_alpha'],
                  color_continuous_scale='RdBu',
                  color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
#fig.show()
st.plotly_chart(fig, use_container_width=True)


st.markdown("# Sunburst: https://plotly.com/python/sunburst-charts/")


st.markdown("# Life Expectancy Sunburst")
df = px.data.gapminder().query("year == 2007")
fig = px.sunburst(df, path=['continent', 'country'], values='pop',
                  color='lifeExp', hover_data=['iso_alpha'],
                  color_continuous_scale='RdBu',
                  color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
st.plotly_chart(fig, use_container_width=True)


st.markdown("# Coffee Aromas and Tastes Sunburst")
df1 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/sunburst-coffee-flavors-complete.csv')
df2 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/coffee-flavors.csv')
fig = go.Figure()
fig.add_trace(go.Sunburst(
    ids=df1.ids,
    labels=df1.labels,
    parents=df1.parents,
    domain=dict(column=0)
))
fig.add_trace(go.Sunburst(
    ids=df2.ids,
    labels=df2.labels,
    parents=df2.parents,
    domain=dict(column=1),
    maxdepth=2
))
fig.update_layout(
    grid= dict(columns=2, rows=1),
    margin = dict(t=0, l=0, r=0, b=0)
)
st.plotly_chart(fig, use_container_width=True)





# Sunburst
#data = dict(
#    character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
#    parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
#    value=[10, 14, 12, 10, 2, 6, 6, 4, 4])
#fig = px.sunburst(
#    data,
#    names='character',
#    parents='parent',
#    values='value',
#)
#fig.show()
#st.plotly_chart(fig, use_container_width=True)


df = px.data.tips()
fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'], 
                 values='total_bill', color='time',
                  color_discrete_map={'(?)':'lightgrey', 'Lunch':'gold', 'Dinner':'darkblue'})
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
#fig.show()
fig.update_traces(marker=dict(cornerradius=5))

st.plotly_chart(fig, use_container_width=True)


df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv')
fig = go.Figure(go.Treemap(
    ids = df.ids,
    labels = df.labels,
    parents = df.parents,
    pathbar_textfont_size=15,
    root_color="lightgrey"
))
fig.update_layout(
    uniformtext=dict(minsize=10, mode='hide'),
    margin = dict(t=50, l=25, r=25, b=25)
)
#fig.show()
st.plotly_chart(fig, use_container_width=True)


df = pd.read_pickle('bloom_dataset.pkl')
fig = px.treemap(df, path=[px.Constant("ROOTS"), 'Macroarea', 'Family', 'Genus', 'Language', 'dataset_name'],
                 values='num_bytes', maxdepth=4)
fig.update_traces(root_color="pink")
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))

st.plotly_chart(fig, use_container_width=True)