meta-introspector / https-streamlit.io-community-llm-hackathon-2023

hackathon
Apache License 2.0
0 stars 1 forks source link

map app #27

Open jmikedupont2 opened 1 year ago

jmikedupont2 commented 1 year ago

Creating a Streamlit app for sharing and managing a map with items for sale using URL parameters is a multi-step process. In this example, I'll guide you through a simplified version of such an app. This example will allow users to add markers with item details to a map using URL parameters. Here's a basic outline:

import streamlit as st
import folium

# Define a function to parse URL parameters and create markers
def parse_url_parameters():
    url = st.experimental_get_query_params()
    if 'lat' in url and 'lon' in url and 'item' in url:
        lat = float(url['lat'][0])
        lon = float(url['lon'][0])
        item = url['item'][0]
        return lat, lon, item
    return None, None, None

# Create a Streamlit app
st.title("Map with Items for Sale")

# Parse URL parameters and create markers
lat, lon, item = parse_url_parameters()

# Create a map
m = folium.Map(location=[lat, lon] if lat and lon else [0, 0], zoom_start=10)

# Add marker if parameters are provided
if lat and lon and item:
    folium.Marker([lat, lon], tooltip=item).add_to(m)

# Display the map
st.write(m)

# Allow users to add markers using form
st.sidebar.header("Add a Marker")
new_lat = st.sidebar.number_input("Latitude")
new_lon = st.sidebar.number_input("Longitude")
new_item = st.sidebar.text_input("Item for Sale")
if st.sidebar.button("Add Marker"):
    if new_lat and new_lon and new_item:
        # Update the URL with new parameters
        st.experimental_set_query_params(lat=[new_lat], lon=[new_lon], item=[new_item])
        # Refresh the page to reflect the changes
        st.experimental_rerun()

# Display current URL parameters
st.sidebar.header("Current URL Parameters")
st.sidebar.write(st.experimental_get_query_params())

Here's a breakdown of how this app works:

  1. Import necessary libraries (Streamlit and Folium).

  2. Define a function (parse_url_parameters) to extract latitude, longitude, and item details from URL parameters.

  3. Create the Streamlit app and set its title.

  4. Parse URL parameters and create a map with an initial marker if parameters are provided.

  5. Allow users to add markers to the map using a form in the sidebar.

  6. Display the current URL parameters in the sidebar.

To use this app, run it using Streamlit and access it through a web browser. You can add markers by entering latitude, longitude, and item details in the sidebar form, and the app will update the map and URL parameters accordingly.

Remember to customize and expand this example to suit your specific requirements for managing and sharing items for sale on a map using Streamlit and URL parameters.

jmikedupont2 commented 1 year ago

The secret data will be stored in jwt like this https://jwtjwt.streamlit.app/?embedded=True&_jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZXNvdXJjZSI6IlRoZSBBbnN3ZXIgdG8gdGhlIFVsdGltYXRlIFF1ZXN0aW9uIG9mIExpZmUsIHRoZSBVbml2ZXJzZSwgYW5kIEV2ZXJ5dGhpbmciLCJleHAiOjE2OTQ2OTczNTl9.vq9DpBxAAHGbW9rnRK7guo-IxPYJd16caFrk6RjydJc&expiration=60&resource=The+Answer+to+the+Ultimate+Question+of+Life%2C+the+Universe%2C+and+Everything&secret=42