File size: 4,027 Bytes
c400da3
3a2fe1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c400da3
3a2fe1d
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import streamlit as st
import pandas as pd
import altair as alt

# ===============================
# 1️⃣ 데이터 뢈러였기
# ===============================

past_path = '/app/src/2018-2024.xlsx'
future_path = '/app/src/μ˜ˆμƒμˆ˜μš”λŸ‰_2025예츑.xlsx'

past_df = pd.read_excel(past_path)
future_df = pd.read_excel(future_path)

past_df['μ›”'] = past_df['μ›”'].astype(int)
future_df['μ›”'] = future_df['μ›”'].astype(int)

past_df = past_df.rename(columns={'νŒλ§€λŸ‰(kg)': 'y'})
future_df = future_df.rename(columns={'μ˜ˆμƒμˆ˜μš”λŸ‰': 'y'})

past_df['y'] = past_df['y'].astype(int)
future_df['y'] = future_df['y'].round().astype(int)

# ===============================
# 2️⃣ νŽ˜μ΄μ§€ μ„€μ • & μŠ€νƒ€μΌ
# ===============================

st.set_page_config(page_title="과일 μˆ˜μš”λŸ‰ λŒ€μ‹œλ³΄λ“œ", layout="wide")

st.markdown("""
    <style>
        /* 타이틀을 더 μ•„λž˜λ‘œ λ‚΄λ €μ„œ 헀더와 κ²ΉμΉ˜μ§€ μ•Šκ²Œ */
        .main > div:first-child {
            padding-top: 50px !important;
        }
        .title {
            font-size: 30px;
            font-weight: 700;
            margin-top: 25px;
            margin-bottom: 20px;
        }
    </style>
""", unsafe_allow_html=True)

# νŽ˜μ΄μ§€ 타이틀
st.markdown("<div class='title'>🍎 과일 μˆ˜μš”λŸ‰ λŒ€μ‹œλ³΄λ“œ (κ³Όκ±° + 2025 예츑)</div>", unsafe_allow_html=True)

# ===============================
# 3️⃣ 데이터 선택
# ===============================

data_type = st.sidebar.radio("πŸ“‚ μ‚¬μš©ν•  데이터", ["κ³Όκ±° 데이터", "2025λ…„ 예츑 데이터"])
selected_df = past_df if data_type == "κ³Όκ±° 데이터" else future_df

# ===============================
# 4️⃣ 년도 선택 (2025λ…„ μ˜ˆμΈ‘μ€ μˆ¨κΉ€)
# ===============================

if data_type == "κ³Όκ±° 데이터":
    available_years = sorted(selected_df['년도'].unique())

    selected_years = st.multiselect(
        "πŸ“… μ‘°νšŒν•  년도",
        available_years,
        default=[]  # κΈ°λ³Έ 선택 μ—†μŒ
    )

    df_filtered = selected_df[selected_df['년도'].isin(selected_years)]
else:
    df_filtered = selected_df.copy()  # 2025λ…„λ§Œ 쑴재 β†’ μžλ™ κ³ μ •

# ===============================
# 5️⃣ 과일 선택 (κΈ°λ³Έ 선택 μ—†μŒ)
# ===============================

fruits = sorted(df_filtered['과일쒅λ₯˜'].unique())

selected_fruits = st.multiselect(
    "🍊 ν‘œμ‹œν•  과일 선택",
    fruits,
    default=[]   # κΈ°λ³Έ 선택 μ—†μŒ
)

df_chart = df_filtered[df_filtered['과일쒅λ₯˜'].isin(selected_fruits)]

# ===============================
# 6️⃣ κ·Έλž˜ν”„ μ˜μ—­
# ===============================

st.subheader("πŸ“ˆ 월별 μˆ˜μš”λŸ‰ κ·Έλž˜ν”„")

if len(df_chart) > 0:

    if data_type == "κ³Όκ±° 데이터":
        years = sorted(df_chart['년도'].unique())
    else:
        years = [2025]

    for y in years:
        st.markdown(f"### πŸ“Œ {y}λ…„")

        df_year = df_chart[df_chart['년도'] == y]

        chart = (
            alt.Chart(df_year)
            .mark_line(point=True)
            .encode(
                x=alt.X('μ›”:O', title='μ›”', axis=alt.Axis(labelAngle=0)),
                y=alt.Y('y:Q', title='μˆ˜μš”λŸ‰'),
                color='과일쒅λ₯˜:N',
                tooltip=['년도', '과일쒅λ₯˜', 'μ›”', 'y']
            )
            .properties(height=350)
        )

        st.altair_chart(chart, use_container_width=True)

else:
    st.info("κ·Έλž˜ν”„μ— ν‘œμ‹œν•  과일을 μ„ νƒν•˜μ„Έμš”.")

# ===============================
# 7️⃣ ν…Œμ΄λΈ” μ˜μ—­
# ===============================

st.subheader("πŸ“Š 상세 데이터")

selected_fruits_table = st.multiselect(
    "πŸ“‹ ν…Œμ΄λΈ” ν‘œμ‹œ 과일",
    fruits,
    default=[]
)

df_table = df_filtered[df_filtered['과일쒅λ₯˜'].isin(selected_fruits_table)]

if len(df_table) > 0:
    df_show = df_table[['년도', 'μ›”', '과일쒅λ₯˜', 'y']].rename(columns={'y': 'μˆ˜μš”λŸ‰'})
    st.dataframe(df_show, use_container_width=True)
else:
    st.info("ν…Œμ΄λΈ”μ— ν‘œμ‹œν•  과일을 μ„ νƒν•˜μ„Έμš”.")