streamlit
1# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from typing import Any, cast16
17import numpy as np18import pandas as pd19
20import streamlit as st21from tests.streamlit import pyspark_mocks22from tests.streamlit.snowpark_mocks import DataFrame as MockedSnowparkDataFrame23from tests.streamlit.snowpark_mocks import Table as MockedSnowparkTable24
25"""
26### Empty map
27"""
28
29st.map()30
31
32"""
33### st.map with pyspark.sql.DataFrame
34"""
35
36st.map(pyspark_mocks.DataFrame(is_map=True))37
38"""
39### st.map with unevaluated Snowpark Table
40"""
41
42st.map(MockedSnowparkTable(is_map=True, num_of_rows=50000))43
44"""
45### st.map with unevaluated Snowpark DataFrame
46"""
47
48st.map(MockedSnowparkDataFrame(is_map=True, num_of_rows=50000))49
50"""
51### Simple map
52"""
53
54# Cast is needed due to mypy not understanding the outcome of dividing
55# an array by a list of numbers.
56np.random.seed(0)57coords: "np.typing.NDArray[np.float_]" = cast(58Any,59np.random.randn(1000, 2) / [50, 50],60) + [37.76, -122.4]61df = pd.DataFrame(coords, columns=["lat", "lon"])62
63st.map(df)64
65
66"""
67### Simple map with zoom
68"""
69
70st.map(df, zoom=8)71
72
73"""
74### Map with color and size layers
75"""
76
77df = pd.DataFrame(78{79"xlat": [38.8762997, 38.8742997, 38.9025842],80"xlon": [-77.0037, -77.0057, -77.0556545],81"color": ["#f00", "#f0f", "#00f"],82"size": [1000, 500, 300],83}84)
85
86st.map(87df,88latitude="xlat",89longitude="xlon",90color="color",91size="size",92)
93