import streamlit as st import pandas as pd astations = [ ["hongkongobservatory","HKO",22.3022566,114.1722662,"Hong Kong Observatory"], ["kingspark","KP",22.3115408,114.1685675,"Observatory Meteorological Station, King's Park"], ] astationcolumns = ['akey','astationcode','alatitude','alongitude','atitle',] acontainer1 = st.empty() acontainer2 = st.empty() acontainer3 = st.empty() def asubmit(aparam): adf2 = aparam["adataframe"] aselecteditem = adf2.loc[adf2["atitle"]==aparam["aselected"], "astationcode"] alink = ("https://data.weather.gov.hk/weatherAPI/opendata/opendata.php?dataType=CLMTEMP&year=2022&rformat=csv&station={}").format(aselecteditem.values[0]) aparam["acontainer"].write(alink) adf = pd.DataFrame( astations, columns=astationcolumns ) aoption = acontainer1.selectbox( 'Which station?', adf['atitle'] ) if acontainer2.button("Submit") == True: asubmit(aparam={"aselected":aoption,"acontainer":acontainer3,"adataframe":adf,})