Hi Guys!
I have been playing around with the uber demo (https://github.com/streamlit/demo-uber-nyc-pickups/blob/master/app.py) and got it to work on my laptop. But after a few modifications I got the following error when streamlit tries to load the Mapbox data: “A valid API access token is required to use Mapbox data”
Changing the code back to the original does not solve this, so I assume this is related to the fact that I have never specified my Mapbox token, but where do I do this?
I tried the steps here “https://github.com/uber/deck.gl/blob/master/docs/get-started/using-with-map.md” and the code snippet I found in another question here:
st.deck_gl_chart(
viewport={
"mapStyle": "mapbox://styles/mapbox/light-v9",
"mapboxApiAccessToken": '<token>',
"latitude": midpoint[0],
"longitude": midpoint[1],
"zoom": 2,
"pitch": 50
},
layers=[
{
"type": "LineLayer",
"data": tracks,
"encoding": {"getLatitude": "lat",
"getLongitude": "lon",
"getTargetLatitude": "to_lat",
"getTargetLongitude": "to_lon",
}
}
]
But with no succes. What is the correct way to do this?
Thanks!
Hi @Killaars,
Thanks your your question. You need a mapbox API token to be able to access the mapStyle via MapBox. MapBox should have documentation on how to do that. This link could be a starting point: https://docs.mapbox.com/help/how-mapbox-works/access-tokens/. Obtaining an API token from MapBox and using it here is very likely the right way to go.
The fact that reverting the code to the original does not fix your problem is more worrying. Have you tried reloading or even using an Incognito window to clear out the possibility of some cookie to be cached and causing this? If that does not work, I can definitely open a bug and follow up on the issue.
Best,
Matteo
Hi Monchier,
Thanks for replying! It appears to be related to some cookie setting, because it works when I open streamlit in Firefox or an incognito window in Chrome. However, the question remains why it works, because I have not specified my token somewhere in the script. So how does Mapbox or Streamlit know what the token is?
Interesting. It turns out we are hardcoding the public Mapbox API token in our code. When you are using the deck_gl_chart
that token is used. This should be the reason why it works without passing a token. We are refactoring this piece of code. We will provide a different way to share the public token and we will give the ability to pass a custom token from the configuration file. I will give you a handle to the Github issue that is describing this work.
Matteo
Thanks for looking into this! The public token would explain the Mapbox tiles, but I think a custom token option would be more practical in the end. Thanks for your help!
1 Like