Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,10 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
# Configuración de la página
|
| 5 |
st.set_page_config(page_title="Generador de Gráficos", layout="wide")
|
| 6 |
|
| 7 |
-
# Estilo de la aplicación
|
| 8 |
-
st.markdown(
|
| 9 |
-
"""
|
| 10 |
-
<style>
|
| 11 |
-
.sidebar .sidebar-content {
|
| 12 |
-
background-color: #f0f2f6;
|
| 13 |
-
}
|
| 14 |
-
.css-1aumxhk {
|
| 15 |
-
display: none;
|
| 16 |
-
}
|
| 17 |
-
.css-1d391kg {
|
| 18 |
-
padding: 2rem 1rem 1rem 1rem;
|
| 19 |
-
}
|
| 20 |
-
</style>
|
| 21 |
-
""",
|
| 22 |
-
unsafe_allow_html=True,
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
# Sidebar para la configuración del gráfico
|
| 26 |
st.sidebar.header("Configuración del Gráfico")
|
| 27 |
|
|
@@ -30,7 +13,7 @@ chart_type = st.sidebar.selectbox("Tipo de Gráfico", ["Línea", "Barras"])
|
|
| 30 |
|
| 31 |
# Ingresar valores para el eje X
|
| 32 |
x_values = st.sidebar.text_area("Valores para X (separados por comas)", "2013,2014,2015,2016,2017")
|
| 33 |
-
x =
|
| 34 |
|
| 35 |
# Ingresar valores para el eje Y
|
| 36 |
y_values = st.sidebar.text_area("Valores para Y (separados por comas)", "10,18,5,9,12")
|
|
@@ -40,41 +23,17 @@ y = [int(i) for i in y_values.split(",")]
|
|
| 40 |
if len(x) != len(y):
|
| 41 |
st.error("Los valores de X y Y deben tener la misma cantidad de elementos.")
|
| 42 |
else:
|
| 43 |
-
#
|
| 44 |
-
data =
|
| 45 |
|
| 46 |
-
#
|
| 47 |
if chart_type == "Línea":
|
| 48 |
-
|
| 49 |
elif chart_type == "Barras":
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# Crear el gráfico con ApexCharts
|
| 53 |
-
st.markdown(
|
| 54 |
-
f"""
|
| 55 |
-
<div id="chart"></div>
|
| 56 |
-
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
| 57 |
-
<script>
|
| 58 |
-
var options = {{
|
| 59 |
-
chart: {{
|
| 60 |
-
type: '{chart_type_js}',
|
| 61 |
-
height: 350
|
| 62 |
-
}},
|
| 63 |
-
series: [{{
|
| 64 |
-
name: 'Valores',
|
| 65 |
-
data: {data}
|
| 66 |
-
}}],
|
| 67 |
-
xaxis: {{
|
| 68 |
-
type: 'category'
|
| 69 |
-
}}
|
| 70 |
-
}};
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
</script>
|
| 75 |
-
""",
|
| 76 |
-
unsafe_allow_html=True,
|
| 77 |
-
)
|
| 78 |
|
| 79 |
# Información adicional
|
| 80 |
-
st.write("Este es un generador básico de gráficos utilizando Streamlit y
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import plotly.express as px
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
# Configuración de la página
|
| 6 |
st.set_page_config(page_title="Generador de Gráficos", layout="wide")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Sidebar para la configuración del gráfico
|
| 9 |
st.sidebar.header("Configuración del Gráfico")
|
| 10 |
|
|
|
|
| 13 |
|
| 14 |
# Ingresar valores para el eje X
|
| 15 |
x_values = st.sidebar.text_area("Valores para X (separados por comas)", "2013,2014,2015,2016,2017")
|
| 16 |
+
x = x_values.split(",")
|
| 17 |
|
| 18 |
# Ingresar valores para el eje Y
|
| 19 |
y_values = st.sidebar.text_area("Valores para Y (separados por comas)", "10,18,5,9,12")
|
|
|
|
| 23 |
if len(x) != len(y):
|
| 24 |
st.error("Los valores de X y Y deben tener la misma cantidad de elementos.")
|
| 25 |
else:
|
| 26 |
+
# Crear un DataFrame
|
| 27 |
+
data = pd.DataFrame({"X": x, "Y": y})
|
| 28 |
|
| 29 |
+
# Generar el gráfico basado en el tipo seleccionado
|
| 30 |
if chart_type == "Línea":
|
| 31 |
+
fig = px.line(data, x="X", y="Y", title="Line Chart")
|
| 32 |
elif chart_type == "Barras":
|
| 33 |
+
fig = px.bar(data, x="X", y="Y", title="Bar Chart")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Mostrar el gráfico
|
| 36 |
+
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Información adicional
|
| 39 |
+
st.write("Este es un generador básico de gráficos utilizando Streamlit y Plotly.")
|