|
import streamlit as st |
|
import pandas as pd |
|
import io |
|
|
|
|
|
def load_city_data(city): |
|
file_path = f"{city.lower()}.json" |
|
return pd.read_json(file_path) |
|
|
|
|
|
def main(): |
|
st.title("Stadt-Daten-Ansicht") |
|
|
|
|
|
with st.sidebar: |
|
st.header("Wähle eine Stadt") |
|
bamberg = st.button("Bamberg") |
|
coburg = st.button("Coburg") |
|
bad_kissingen = st.button("Kissingen") |
|
|
|
|
|
data = None |
|
if bamberg: |
|
data = load_city_data("Bamberg") |
|
st.subheader("Daten für Bamberg") |
|
|
|
if coburg: |
|
data = load_city_data("Coburg") |
|
st.subheader("Daten für Coburg") |
|
|
|
if bad_kissingen: |
|
data = load_city_data("Kissingen") |
|
st.subheader("Daten für Bad Kissingen") |
|
|
|
if data is not None: |
|
|
|
col1, col2 = st.columns([3, 1]) |
|
with col1: |
|
st.dataframe(data, width=1000) |
|
with col2: |
|
|
|
excel_buffer = io.BytesIO() |
|
data.to_excel(excel_buffer, index=False) |
|
excel_buffer.seek(0) |
|
st.download_button( |
|
label="Download Excel", |
|
data=excel_buffer, |
|
file_name="data.xlsx", |
|
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" |
|
) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|