The entire code is tied together to produce the interactive webmap. _child( (, labels=False) )įilter the metadata on clicking the map: state = '' if st_map: state = st_map return state state = display_state_filter(df_country, state) #grab the state from the functionĬreate filters on the sidebars to select the year, season, crop and state def display_time_filters(df): year_list = + list(df.unique()) #use to create an empty selection year_list.sort(reverse=True) year = st.lectbox('Year', year_list) season_list = + list(df.unique()) season = st.lectbox('Season', season_list) st.header(f'') return year, season def crop_filter(df): crop_list = + list(df.unique()) crop_list.sort() return st.lectbox('Crop', crop_list) def display_state_filter(df, state): state_list = + list(df.unique()) state_list.sort() state_index = state_list.index(state) if state and state in state_list else 0 #display state only it is in state_list else select the first index return st.lectbox('State', state_list, state_index) The geojson file contains the state name under “st_nm” properties section: choropleth = folium.Choropleth( geo_data = 'data/states_india.geojson', data = df, columns=('State', 'Yield'), key_on= '_nm', line_opacity=0.8, highlight=True ) _to(map)Ĭreate a child element for the choropleth geojson object to display the state name while hovering over the map. Import the streamlit library to create the basic skeleton: import streamlit as st APP_TITLE = 'Agriculture Crop Production in India' APP_SUB_TITLE = 'Source: Ministry of Agriculture and Farmers Welfare of India' def main(): st.set_page_config(APP_TITLE) #set page config for APP_TITLE st.title(APP_TITLE) st.caption(APP_SUB_TITLE) if _name_ = "_main_": main() Install the requirements for creating the webmap: pandas=1.2.4 folium=0.12.1.post1 streamlit=1.10.0 streamlit_folium=0.6.13 Installing and creating the skeleton on the web map I obtained the crop data from the government website, Ministry of Agriculture and Farmers welfare.įor creating the map, I’ll use the Python Folium Library, and for boundary I’ll use the India GeoJSON file. My goal was to visualize agriculture crop production of India across different years and for different crops. Python can be used to convert an ordinary csv file into an interactive web map. 'Ordinary World' centers on the mid-life crisis of a husband and father who, on his 40th birthday, decides to revisit his punk-rock past by throwing an extravagant party in the presidential suite of the Drake Hotel - where he encounters his beautiful ex-girlfriend and former bandmates who have since moved on to bigger and better things. Interactive webmap using Python Streamlit - Agriculture Production in India
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |