Streamlit returns 错误,如果 get_elevation 添加到 ColumnLayer
Streamlit returns error if get_elevation added to ColumnLayer
我是 streamlit
的新手,我正在尝试显示带有列的 pydeck
图层。我希望列高是我在数据框中提供的 rain (mm)
列,但每当我使用 get_evelation="rain (mm)"
时,我都会收到以下错误:
Error: Function calls not allowed in JSON expressions
at http://localhost:8501/static/js/7.f6560317.chunk.js:2:512302
at u (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512666)
at http://localhost:8501/static/js/7.f6560317.chunk.js:2:512596
at Array.forEach (<anonymous>)
at u (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512568)
at u (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512673)
at t.default (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512250)
at e.h [as convertFunction] (http://localhost:8501/static/js/7.f6560317.chunk.js:2:1049691)
at http://localhost:8501/static/js/7.f6560317.chunk.js:2:2778265
at y (http://localhost:8501/static/js/7.f6560317.chunk.js:2:2778495)
我用来渲染地图的函数如下:
def make_map2(data, lat, lon, zoom):
column_layer = pdk.Layer(
"ColumnLayer",
data=data,
get_position=["lon", "lat"],
get_elevation="rain (mm)",
elevation_scale=20,
radius=2000,
get_fill_color=[180, 0, 200, 140],
pickable=True,
auto_highlight=True,
extruded=True
)
tooltip={'html': 'Location: {location}</br> Date: {date} </br> Rainfall (mm): {rain_mm}</br> Type: {type}'}
r = pdk.Deck(column_layer,
initial_view_state={
"latitude": lat,
"longitude": lon,
"zoom": zoom,
"pitch": 60
},
tooltip=tooltip,
map_provider="mapbox",
map_style='mapbox://styles/mapbox/light-v9',
)
map2 = st.write(r)
return map2
输入数据具有以下结构:
date location lat lon rain (mm) type
0 2021-09-15 lowestoft 52.483 1.727 54.115513 predicted
1 2021-09-15 heathrow 51.479 -0.449 30.008739 predicted
2 2021-09-15 eastbourne 50.762 0.285 90.584396 predicted
3 2021-09-15 cambridge 52.245 0.102 51.445862 predicted
4 2021-09-15 manston 51.346 1.337 81.089737 predicted
5 2021-09-15 oxford 51.761 -1.262 39.420902 predicted
这可以像参数拼写错误一样简单:
get_evelation="rain (mm)"
应该是 get_elevation="rain (mm)"
编辑:无论参数名称拼写错误如何,pydeck 解析字符串文字时都会出现此错误。 pydeck 假设 rain (mm)
是一个函数调用,并抛出一个错误。在不带空格或括号的情况下命名 get_elevation
列允许示例工作:
import pandas as pd
import numpy as np
import streamlit as st
import pydeck as pdk
df = pd.read_csv("~/Desktop/data.csv")
#to prove hypothesis, make column name one continuous string with no extra characters
df["rain_noparens"] = df["rain (mm)"]
view = pdk.data_utils.compute_view(df[["lon", "lat"]])
view.pitch = 75
view.bearing = 60
column_layer = pdk.Layer(
"ColumnLayer",
data=df,
get_position=["lon", "lat"],
get_elevation="rain_noparens",
elevation_scale=20,
radius=2000,
get_fill_color=[180, 0, 200, 140],
pickable=True,
auto_highlight=True,
)
tooltip = {
"html": "Location: {location}</br> Date: {date} </br> Rainfall (mm): {rain (mm)}</br> Type: {type}"
}
r = pdk.Deck(
column_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style="mapbox://styles/mapbox/light-v9",
)
st.pydeck_chart(r)
我是 streamlit
的新手,我正在尝试显示带有列的 pydeck
图层。我希望列高是我在数据框中提供的 rain (mm)
列,但每当我使用 get_evelation="rain (mm)"
时,我都会收到以下错误:
Error: Function calls not allowed in JSON expressions
at http://localhost:8501/static/js/7.f6560317.chunk.js:2:512302
at u (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512666)
at http://localhost:8501/static/js/7.f6560317.chunk.js:2:512596
at Array.forEach (<anonymous>)
at u (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512568)
at u (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512673)
at t.default (http://localhost:8501/static/js/7.f6560317.chunk.js:2:512250)
at e.h [as convertFunction] (http://localhost:8501/static/js/7.f6560317.chunk.js:2:1049691)
at http://localhost:8501/static/js/7.f6560317.chunk.js:2:2778265
at y (http://localhost:8501/static/js/7.f6560317.chunk.js:2:2778495)
我用来渲染地图的函数如下:
def make_map2(data, lat, lon, zoom):
column_layer = pdk.Layer(
"ColumnLayer",
data=data,
get_position=["lon", "lat"],
get_elevation="rain (mm)",
elevation_scale=20,
radius=2000,
get_fill_color=[180, 0, 200, 140],
pickable=True,
auto_highlight=True,
extruded=True
)
tooltip={'html': 'Location: {location}</br> Date: {date} </br> Rainfall (mm): {rain_mm}</br> Type: {type}'}
r = pdk.Deck(column_layer,
initial_view_state={
"latitude": lat,
"longitude": lon,
"zoom": zoom,
"pitch": 60
},
tooltip=tooltip,
map_provider="mapbox",
map_style='mapbox://styles/mapbox/light-v9',
)
map2 = st.write(r)
return map2
输入数据具有以下结构:
date location lat lon rain (mm) type
0 2021-09-15 lowestoft 52.483 1.727 54.115513 predicted
1 2021-09-15 heathrow 51.479 -0.449 30.008739 predicted
2 2021-09-15 eastbourne 50.762 0.285 90.584396 predicted
3 2021-09-15 cambridge 52.245 0.102 51.445862 predicted
4 2021-09-15 manston 51.346 1.337 81.089737 predicted
5 2021-09-15 oxford 51.761 -1.262 39.420902 predicted
这可以像参数拼写错误一样简单:
get_evelation="rain (mm)"
应该是 get_elevation="rain (mm)"
编辑:无论参数名称拼写错误如何,pydeck 解析字符串文字时都会出现此错误。 pydeck 假设 rain (mm)
是一个函数调用,并抛出一个错误。在不带空格或括号的情况下命名 get_elevation
列允许示例工作:
import pandas as pd
import numpy as np
import streamlit as st
import pydeck as pdk
df = pd.read_csv("~/Desktop/data.csv")
#to prove hypothesis, make column name one continuous string with no extra characters
df["rain_noparens"] = df["rain (mm)"]
view = pdk.data_utils.compute_view(df[["lon", "lat"]])
view.pitch = 75
view.bearing = 60
column_layer = pdk.Layer(
"ColumnLayer",
data=df,
get_position=["lon", "lat"],
get_elevation="rain_noparens",
elevation_scale=20,
radius=2000,
get_fill_color=[180, 0, 200, 140],
pickable=True,
auto_highlight=True,
)
tooltip = {
"html": "Location: {location}</br> Date: {date} </br> Rainfall (mm): {rain (mm)}</br> Type: {type}"
}
r = pdk.Deck(
column_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style="mapbox://styles/mapbox/light-v9",
)
st.pydeck_chart(r)