creadordetablas / app.py
GAS17's picture
Create app.py
f62d38b verified
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# Define function to create and display styled table with highlighted header
def create_styled_table_highlighted_header(data, title):
df = pd.DataFrame(data)
fig, ax = plt.subplots(figsize=(12, len(df)*0.7 + 2)) # Adjusting figure size for larger cell height and full image coverage
ax.axis('tight')
ax.axis('off')
# Add title
plt.title(title, fontsize=20, weight='bold', fontname='Lato', pad=10)
table = ax.table(cellText=df.values, colLabels=df.columns, cellLoc='center', loc='center')
# Styling the table
table.auto_set_font_size(False)
table.set_fontsize(14)
table.scale(1.2, 1.5) # Adjusting scale for larger cells
# Setting all cells to white
rows = len(df)
cols = len(df.columns)
for i in range(rows):
for j in range(cols):
table[(i+1, j)].set_facecolor('white')
# Highlighting header
for j in range(cols):
table[(0, j)].set_facecolor('#a9a9a9') # Dark grey color
# Adjusting column width
table.auto_set_column_width([0, 1, 2])
# Displaying the table as an image
st.pyplot(fig)
# Streamlit app
st.title('Actividades Culturales')
# Form to input activity data
with st.form("activity_form"):
title = st.text_input("Título de la actividad")
days = st.text_area("Días (separados por comas)")
schedules = st.text_area("Horarios (separados por comas, en el mismo orden que los días)")
activities = st.text_area("Actividades (separadas por comas, en el mismo orden que los días y horarios)")
submit_button = st.form_submit_button(label='Crear Tabla')
if submit_button:
# Parse the input data
days_list = [day.strip() for day in days.split(',')]
schedules_list = [schedule.strip() for schedule in schedules.split(',')]
activities_list = [activity.strip() for activity in activities.split(',')]
# Create the data dictionary
data = {
"Días": days_list,
"Horario": schedules_list,
"Actividad": activities_list
}
# Create and display the table
create_styled_table_highlighted_header(data, title)