dashboard from data coming from mysql
Drop files here
or click to upload
import streamlit as st
import pandas as pd
from sqlalchemy import create_engine
# Create a database engine
engine = create_engine('mysql+mysqlconnector://user:password@host:port/database')
# Load data from MySQL
@st.cache_data
def load_data(query):
with engine.connect() as connection:
return pd.read_sql(query, connection)
st.title('MySQL Dashboard')
# User input for the SQL query
query = st.text_area('SQL Query', '''SELECT * FROM your_table LIMIT 100''')
if st.button('Execute'):
try:
data = load_data(query)
st.write(data)
st.table(data)
except Exception as e:
st.error(f'Error executing the query: {e}')
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?