tx3bas commited on
Commit
e00bb68
·
verified ·
1 Parent(s): 452cdfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -13
app.py CHANGED
@@ -1,22 +1,45 @@
1
  import streamlit as st
2
  import matplotlib.pyplot as plt
3
  import pandas as pd
 
4
 
5
- # Título de la aplicación
6
- st.title("Generador de Gráficos")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Sidebar para la configuración del gráfico
9
- st.sidebar.header("Configuración del Gráfico")
 
 
 
 
 
 
 
10
 
11
- # Tipo de gráfico
12
- chart_type = st.sidebar.selectbox("Tipo de Gráfico", ["Línea", "Barras"])
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 = [int(i) for i in 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")
20
  y = [int(i) for i in y_values.split(",")]
21
 
22
  # Verificar si las listas tienen el mismo tamaño
@@ -24,16 +47,18 @@ if len(x) != len(y):
24
  st.error("Los valores de X y Y deben tener la misma cantidad de elementos.")
25
  else:
26
  # Generar el gráfico basado en el tipo seleccionado
27
- if chart_type == "Línea":
28
  fig, ax = plt.subplots()
29
- ax.plot(x, y, color='red', linewidth=1)
30
- ax.set_title("Line Chart")
 
31
  st.pyplot(fig)
32
 
33
- elif chart_type == "Barras":
34
  fig, ax = plt.subplots()
35
- ax.bar(x, y, color='skyblue', edgecolor='blue')
36
- ax.set_title("Bar Chart")
 
37
  st.pyplot(fig)
38
 
39
  # Información adicional
 
1
  import streamlit as st
2
  import matplotlib.pyplot as plt
3
  import pandas as pd
4
+ import streamlit_option_menu as option_menu
5
 
6
+ # Configuración de la página
7
+ st.set_page_config(page_title="Generador de Gráficos", layout="wide")
8
+
9
+ # Estilo de la aplicación
10
+ st.markdown(
11
+ """
12
+ <style>
13
+ .sidebar .sidebar-content {
14
+ background-color: #f0f2f6;
15
+ }
16
+ .css-1aumxhk {
17
+ display: none;
18
+ }
19
+ </style>
20
+ """,
21
+ unsafe_allow_html=True,
22
+ )
23
 
24
  # Sidebar para la configuración del gráfico
25
+ with st.sidebar:
26
+ selected = option_menu.option_menu(
27
+ menu_title="Configuración del Gráfico",
28
+ options=["Línea", "Barras"],
29
+ icons=["graph-up", "bar-chart"],
30
+ menu_icon="cast",
31
+ default_index=0,
32
+ )
33
 
34
+ # Título de la aplicación
35
+ st.title("Generador de Gráficos")
36
 
37
  # Ingresar valores para el eje X
38
+ x_values = st.text_area("Valores para X (separados por comas)", "2013,2014,2015,2016,2017")
39
  x = [int(i) for i in x_values.split(",")]
40
 
41
  # Ingresar valores para el eje Y
42
+ y_values = st.text_area("Valores para Y (separados por comas)", "10,18,5,9,12")
43
  y = [int(i) for i in y_values.split(",")]
44
 
45
  # Verificar si las listas tienen el mismo tamaño
 
47
  st.error("Los valores de X y Y deben tener la misma cantidad de elementos.")
48
  else:
49
  # Generar el gráfico basado en el tipo seleccionado
50
+ if selected == "Línea":
51
  fig, ax = plt.subplots()
52
+ ax.plot(x, y, color='#FF5C5C', linewidth=2)
53
+ ax.set_title("Line Chart", fontsize=20, fontweight='bold')
54
+ ax.grid(True, linestyle='--', alpha=0.5)
55
  st.pyplot(fig)
56
 
57
+ elif selected == "Barras":
58
  fig, ax = plt.subplots()
59
+ ax.bar(x, y, color='#5CCFFF', edgecolor='blue', linewidth=2)
60
+ ax.set_title("Bar Chart", fontsize=20, fontweight='bold')
61
+ ax.grid(True, linestyle='--', alpha=0.5)
62
  st.pyplot(fig)
63
 
64
  # Información adicional