import altair as alt import numpy as np import pandas as pd import streamlit as st """ # Welcome to Streamlit! Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:. If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community forums](https://discuss.streamlit.io). In the meantime, below is an example of what you can do with just a few lines of code: """ num_points = st.slider("Number of points in spiral", 1, 10000, 1100) num_turns = st.slider("Number of turns in spiral", 1, 300, 31) indices = np.linspace(0, 1, num_points) theta = 2 * np.pi * num_turns * indices radius = indices x = radius * np.cos(theta) y = radius * np.sin(theta) df = pd.DataFrame({ "x": x, "y": y, "idx": indices, "rand": np.random.randn(num_points), }) st.altair_chart(alt.Chart(df, height=700, width=700) .mark_point(filled=True) .encode( x=alt.X("x", axis=None), y=alt.Y("y", axis=None), color=alt.Color("idx", legend=None, scale=alt.Scale()), size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])), )) tab1, tab2 = st.tabs(["PySpark", "General"]) with tab1: from pyspark.sql import SparkSession spark = SparkSession.builder \ .appName('ml') \ .getOrCreate() archivo = st.file_uploader("Sube tu archivo", type = ['txt', 'csv']) if archivo is not None: texto = archivo.read().decode("utf-8") if texto: st.write(texto) with tab2: ''' # Este es un encabezado de nivel 1 ## Este es uno de nivel 2 Y podemos usar _cursivas_, *negritas*, [vínculos](google.com)... ''' # Entrada de texto nombre = st.text_input('Escribe tu nombre') # Barra deslizante nacimiento = st.slider('¿En qué año naciste?', 1940, 2024, help = 'Desliza el selector hasta tu año de nacimiento') if 2024 - nacimiento > 18: st.write(f'Eres mayor de edad y al terminar este año deberías tener {2024 - nacimiento} años 🥳') saludo = '' # Botón if len(nombre) > 0: if st.button('Di hola'): saludo = f'¡Hola {nombre}!' if st.button('Borrar saludo'): saludo = '' st.write(saludo) # Select o combobox color = st.selectbox('Elige tu color favorito', ['rojo', 'verde', 'azul'], index = None, placeholder = 'Color...' ) if color != None: st.write(f'Tu color favorito es {color}') import pandas as pd df = pd.DataFrame({ 'numeros' : [1, 2, 3, 4], 'letras' : ['a', 'b', 'c', 'd'] }) st.write(df) import matplotlib.pyplot as plt fig = plt.figure() plt.scatter(df.numeros, df.letras) st.pyplot(fig)