import streamlit as st import pydeck as pdk import numpy as np # Define a data set data = np.random.randn(1000, 2) * 0.1 layer = pdk.Layer( "ScatterplotLayer", data=data, get_position="[0, 1]", get_color="[200, 30, 0, 160]", get_radius=50, ) # Define a Pydeck view state view_state = pdk.ViewState(latitude=37.7749, longitude=-122.4194, zoom=11) # Define Pydeck initial rendering options initial_options = pdk.Deck( map_style="mapbox://styles/mapbox/dark-v9", layers=[layer], initial_view_state=view_state, ) # Define the HTML template for the Three.js canvas html_template = """
""" # Define the Streamlit app def app(): # Define a Pydeck map using a ScatterplotLayer st.pydeck_chart(initial_options) # Add a dropdown menu to select Pydeck layer types layer_type = st.selectbox("Layer type", ["HexagonLayer", "HeatmapLayer", "ScatterplotLayer"]) # Add sliders to adjust the Pydeck layer properties if layer_type == "HexagonLayer": layer.radius = st.slider("Radius", 10, 100, 50) layer.elevation_scale = st.slider("Elevation scale", 0, 10, 1) layer.elevation_range = st.slider("Elevation range", 0, 1000, 100) layer.pickable = st.checkbox("Pickable", True) layer.auto_highlight = st.checkbox("Auto highlight", True) elif layer_type == "HeatmapLayer": layer.intensity = st.slider("Intensity", 0, 10, 1) layer.radius = st.slider("Radius", 10, 100, 50) layer.color_range = st.color_picker("Color range", ["#008000", "#FFFF00", "#FF0000"]) layer.opacity = st.slider("Opacity", 0, 1, 0.8) layer.blend_mode = st.selectbox("Blend mode", ["additive", "multiply"]) elif layer_type == "ScatterplotLayer": layer.get_position = "[0, 1, 2]" layer.get_color = "[200, 30, 0, 160]" layer.get_radius = st.slider("Radius", 10, 100, 50) # Add the updated Pydeck layer to the map #st.pydeck_chart(pdk.Deck(layers=[layer], initial_view_state=view_state)) st.pydeck_chart(pdk.Deck(layers=[layer])) # Add the Three.js canvas to the Streamlit app st.components.v1.html(html_template, height=500) if name == "main": app() # This app has a Pydeck map that displays a scatterplot layer by default, and it allows the user to switch between HexagonLayer, HeatmapLayer, and ScatterplotLayer using a dropdown menu. The user can also adjust the properties of the selected layer using sliders and color pickers. Finally, the app displays a Three.js canvas that rotates a green cube.