create an app that uses st.map to display a map, the source data should be a data frame, allow me to select rows in such data frame and those selected rows should be visible in the map. generate fake data for spots in NYC
Drop files here
or click to upload
import streamlit as st
import pandas as pd
import numpy as np
# Generate fake data for spots in NYC
np.random.seed(0)
num_spots = 100
nyc_lat = np.random.uniform(40.700, 40.800, num_spots)
nyc_lon = np.random.uniform(-74.020, -73.900, num_spots)
# Create a DataFrame
spots_df = pd.DataFrame({
'latitude': nyc_lat,
'longitude': nyc_lon,
'name': [f'Spot {i+1}' for i in range(num_spots)]
})
st.title('NYC Map with Spot Selection')
# Display the DataFrame and allow row selection
selected_rows = st.multiselect('Select spots to display on the map:',
options=spots_df['name'],
default=spots_df['name'].tolist()[:3])
# Filter DataFrame based on selection
selected_spots = spots_df[spots_df['name'].isin(selected_rows)]
# Display selected spots on the map
st.map(selected_spots)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?