tx3bas commited on
Commit
ab48cc8
·
verified ·
1 Parent(s): 7202737

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -30
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- import matplotlib.pyplot as plt
3
 
4
  # Configuración de la página
5
  st.set_page_config(page_title="Generador de Gráficos", layout="wide")
@@ -17,22 +17,6 @@ st.markdown(
17
  .css-1d391kg {
18
  padding: 2rem 1rem 1rem 1rem;
19
  }
20
- .stButton>button {
21
- background-color: #4CAF50;
22
- color: white;
23
- border: none;
24
- padding: 10px 24px;
25
- text-align: center;
26
- text-decoration: none;
27
- display: inline-block;
28
- font-size: 16px;
29
- margin: 4px 2px;
30
- cursor: pointer;
31
- border-radius: 12px;
32
- }
33
- .stButton>button:hover {
34
- background-color: #45a049;
35
- }
36
  </style>
37
  """,
38
  unsafe_allow_html=True,
@@ -56,20 +40,41 @@ y = [int(i) for i in y_values.split(",")]
56
  if len(x) != len(y):
57
  st.error("Los valores de X y Y deben tener la misma cantidad de elementos.")
58
  else:
59
- # Generar el gráfico basado en el tipo seleccionado
60
- if chart_type == "Línea":
61
- fig, ax = plt.subplots()
62
- ax.plot(x, y, color='#FF5C5C', linewidth=2)
63
- ax.set_title("Line Chart", fontsize=20, fontweight='bold')
64
- ax.grid(True, linestyle='--', alpha=0.5)
65
- st.pyplot(fig)
66
 
 
 
 
67
  elif chart_type == "Barras":
68
- fig, ax = plt.subplots()
69
- ax.bar(x, y, color='#5CCFFF', edgecolor='blue', linewidth=2)
70
- ax.set_title("Bar Chart", fontsize=20, fontweight='bold')
71
- ax.grid(True, linestyle='--', alpha=0.5)
72
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  # Información adicional
75
- st.write("Este es un generador básico de gráficos utilizando Streamlit en Hugging Face Spaces.")
 
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")
 
17
  .css-1d391kg {
18
  padding: 2rem 1rem 1rem 1rem;
19
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  </style>
21
  """,
22
  unsafe_allow_html=True,
 
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
+ # Convertir los datos a un formato JSON para ApexCharts
44
+ data = [{"x": x[i], "y": y[i]} for i in range(len(x))]
 
 
 
 
 
45
 
46
+ # Definir el tipo de gráfico
47
+ if chart_type == "Línea":
48
+ chart_type_js = "line"
49
  elif chart_type == "Barras":
50
+ chart_type_js = "bar"
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
+ var chart = new ApexCharts(document.querySelector("#chart"), options);
73
+ chart.render();
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 ApexCharts en Hugging Face Spaces.")