File size: 1,277 Bytes
3184fc6
 
 
 
 
 
 
 
 
 
09a6ab5
3184fc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st
import os
import matplotlib.pyplot as plt
from database_interface.utils import *
st.set_page_config(
    page_title='DataBoard' ,
    page_icon= plt.imread(os.path.abspath('static/logo.png')),
)
st.sidebar.title('DataBases')

cnx = get_connection(user=st.secrets.db_username, password=st.secrets.db_password, host=st.secrets.db_host)

if 'databases' not in st.session_state :
    databases = [db[0] for db in get_database_names(cnx)]
    st.session_state.databases = databases

def on_table_radio_change(db_name) :
    if db_name in st.session_state :
        table_selected = st.session_state.get(db_name)
        st.session_state.table_selected = table_selected
        st.dataframe(get_table_in_database(cnx,db_name = db_name, table_name= table_selected))




with st.sidebar :
    for db in st.session_state.databases :
        with st.expander(db) :
            tables = get_all_tables_in_database(cnx, db)
            tables = [table[0] for table in tables]

            table_selected = st.radio(
                label = 'tables',
                options= tables,
                label_visibility='collapsed' ,
                key = db  ,
                on_change = on_table_radio_change,
                kwargs={"db_name" : db}

            )