Created
September 1, 2020 19:43
-
-
Save poltys/96c433a32db01324e3869627946f9d2c to your computer and use it in GitHub Desktop.
Streamlit DB connector using pymysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import streamlit as st | |
import pymysql | |
from sqlalchemy import create_engine | |
st.sidebar.header('User Input Parameters') | |
date = pd.datetime.today() | |
server = st.sidebar.text_input('Server Name', '') | |
data_mart = st.sidebar.text_input('Data Mart', '') | |
password = st.sidebar.text_input('Password', '') | |
schema = st.sidebar.text_input('Schema', '') | |
st.sidebar.info('In our use case table can be: ') | |
table_name = st.sidebar.text_input('Table Name', '') | |
table = 'SELECT * FROM ' + table_name | |
con = pymysql.connect(server, data_mart, password, schema) | |
data = pd.read_sql(table, con) | |
df = pd.DataFrame(data) | |
df.to_csv(f'local\{table_name}.csv') | |
data = pd.read_csv(f'local\{table_name}.csv') | |
df = pd.DataFrame(data) | |
st.header('Streamlit DB connector') | |
st.subheader(f'Data to be analyzed from {table_name} table in server {server}') | |
st.markdown(df.columns) | |
st.dataframe(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment