File size: 1,148 Bytes
1874f00
 
4e48f26
1874f00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 os
os.environ["STREAMLIT_HOME"] = "/tmp/.streamlit"  # supaya tidak error permission

import streamlit as st
import mysql.connector
import pandas as pd
import io

DB_CONFIG = {
    'host': os.environ.get('DB_HOST'),
    'user': os.environ.get('DB_USER'),
    'password': os.environ.get('DB_PASS'),
    'database': os.environ.get('DB_NAME')
}

st.title("Download Data Survey Face Wash")

try:
    conn = mysql.connector.connect(**DB_CONFIG)
    df = pd.read_sql("SELECT * FROM Kansei", conn)
    conn.close()
except Exception as e:
    st.error(f"Gagal mengambil data dari database: {e}")
    st.stop()

if df.empty:
    st.write("Data survey belum tersedia.")
else:
    st.write(f"Jumlah data: {len(df)}")
    st.dataframe(df)

    output = io.BytesIO()
    with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
        df.to_excel(writer, index=False, sheet_name='Survey Data')
    data_excel = output.getvalue()

    st.download_button(
        label="Download Data Survey (Excel)",
        data=data_excel,
        file_name='survey_data.xlsx',
        mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    )