#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 31 15:01:56 2021
@author: benjaminull
"""
import streamlit as st
import pandas as pd
import numpy as np
import io
import pybase64 as base64
from plotly import graph_objs as go
from datetime import datetime
import plotly.express as px
def get_table_excel_link(df, selected_stocks):
towrite = io.BytesIO()
downloaded_file = df.to_excel(towrite, encoding='utf-8', index=False,
header=True)
towrite.seek(0) # reset pointer
file_name = 'Data'+ selected_stocks+'.xlsx'
style = 'style="color:black;text-decoration: none; font-size:18px;"'
name_mark = "Descargar " + selected_stocks + ".xlsx"
b64 = base64.b64encode(towrite.read()).decode() # some strings
linko= f'
'
return linko
@st.cache(show_spinner=True)
def charged_data():
regiones = {}
regiones['Latam'] = ['Argentina', 'Brazil', 'Chile', 'Colombia',
'Mexico', 'Peru']
regiones['Europa'] = ['Italy', 'Spain', 'Germany', 'United Kingdom',
'France']
regiones['Asia Emergente'] = ['South Korea', 'Taiwan', 'Hong Kong',
'India', 'Thailand', 'Indonesia']
regiones['USA'] = ['United States']
data_dict=np.load('dict_movilidad.npy', allow_pickle='TRUE').item()
return data_dict, regiones
def comandos_utiles():
st.code("""CMD o Terminal\n> pip install streamlit """, language='python')
st.code("""CMD o Terminal\n> cd "ruta vista" \n> streamlit run app.py """,language='python')
code='''import streamlit as st \ndef comandos_utiles(): \n col1, col2 = st.columns(2) \n ...'''
st.code(code, language='python')
st.subheader("Elementos interactivos")
col1, col2 = st.columns(2)
col2.header(" ")
code2=('''var = col1.selectbox("Selectbox", ["Opcion 1", "Opcion 2", "Opcion 3"]) \nst.write(var)''')
col2.code(code2)
var = col1.selectbox("Selectbox", ["Opcion 1", "Opcion 2", "Opcion 3"])
col1.write(var)
var2 = col1.multiselect("Multiselect", ["Opcion 1", "Opcion 2", "Opcion 3"])
col1.write(var2)
code3=('''var = col1.multiselect("Selectbox", ["Opcion 1", "Opcion 2", "Opcion 3"]) \nst.write(var2)''')
col2.header(" ")
col2.code(code3)
var3 = col1.number_input("Number input")
col1.write(var3)
code4=('''var3 = col1.number_input("Number input") \nst.write(var3)''')
col2.header(" ")
col2.code(code4)
st.subheader("Tablas")
col1, col2 = st.columns(2)
df=pd.DataFrame([["1","2","3"],["2","5","6"],["7","8","9"]])
col1.write(df)
col2.header(" ")
col2.code("col1.write(df)")
col1.table(df)
col2.header(" ")
col2.header(" ")
col2.code("col1.table(df)")
col2.header(" ")
code_exc="""import io \nimport pybase64 as base6 \ndef get_table_excel_link(df, name):
towrite = io.BytesIO()
downloaded_file = df.to_excel(towrite, encoding='utf-8', index=False,
header=True)
towrite.seek(0) # reset pointer
file_name = 'Data'+ name +'.xlsx'
style = 'style="color:black;text-decoration: none; font-size:18px;"'
name_mark = "Descargar " + name + ".xlsx"
b64 = base64.b64encode(towrite.read()).decode() # some strings
linko= f''
return linko \ncol1.markdown(get_table_excel_link(df, "tabla 1"),unsafe_allow_html=True)
"""
col1.subheader("Descargar data frame")
col2.header(" ")
col1.header(" ")
col1.header(" ")
col2.code(code_exc)
col1.markdown(get_table_excel_link(df, "tabla 1"),unsafe_allow_html=True)
st.subheader("Graficos")
col1, col2 = st.columns((2,1))
col2.code("col1, col2 = st.columns((2,1)) \nfrom plotly import graph_objs as go \nimport plotly.express as px ")
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", trendline="ols")
st.plotly_chart(fig)
st.code("""df = px.data.tips() \nfig = px.scatter(df, x="total_bill", y="tip", trendline="ols")\ncol1.plotly_chart(fig)""")