Skip to content

Showing an error when it's not localhost and has no mapbox token#1295

Merged
arraydude merged 37 commits intostreamlit:developfrom
arraydude:showingTokenErrorWhenNotLocalhost
May 27, 2020
Merged

Showing an error when it's not localhost and has no mapbox token#1295
arraydude merged 37 commits intostreamlit:developfrom
arraydude:showingTokenErrorWhenNotLocalhost

Conversation

@arraydude
Copy link
Copy Markdown
Contributor

@arraydude arraydude commented Apr 2, 2020

Issue: Fix #1136 #812

Description: As it is not possible to render a Mapbox without any token we are delimiting the use locally.

  • Prevent fetching token when it's not localhost or hello.py
  • Using axios instead of fetch
  • Added new step for cypress job in which we set the mapbox token
  • Unittest

Contribution License Agreement

By submiting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@arraydude arraydude requested a review from a team as a code owner April 2, 2020 23:34
@arraydude arraydude added WIP and removed paused labels Apr 28, 2020
@arraydude arraydude removed the WIP label Apr 29, 2020
@arraydude arraydude requested a review from Amey-D April 29, 2020 22:14
<a href="https://mapbox.com">https://mapbox.com</a>. It's free! (for moderate usage levels) See
<a href="https://docs.streamlit.io/cli.html#view-all-config-options">our documentation</a> for more
info on how to set config options.
`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I was going to comment on this error message, but I need to see it in action to really understand what it should say. Can you give me an example of how to see it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could run for example /e2e/scripts/st_map.py without setting any mapbox token within your config.toml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it looks
Screen Shot 2020-04-30 at 2 19 27 PM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the following snippet when I run streamlit config view:

[mapbox]

# Configure Streamlit to use a custom Mapbox token for elements like st.deck_gl_chart and st.map. If you don't do this you'll be using Streamlit's own token, which has limitations and is not guaranteed to always work. To get a token for yourself, create an account at https://mapbox.com. It's free! (for moderate usage levels)
# Default: ""
token = ""

I wonder if we need to change the comment in the config, because with these change the user will no longer be using Streamlit's own token unless they are running streamlit hello locally.

EDIT: I believe the config comments are at

_create_option(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!, thank you @Amey-D

@tvst
Copy link
Copy Markdown
Contributor

tvst commented Apr 30, 2020

I just realized, before we release this change we should sync with @randyzwitch on how to inform the community, and what changes we need to add for our docs.

(Randy, if you're reading this and are confused about what's going on, PTAL at #1136 for more info)

Copy link
Copy Markdown
Contributor

@Amey-D Amey-D left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great! Added a couple of suggestion primarily to minimize user confusion around this change. PTAL.

<a href="https://mapbox.com">https://mapbox.com</a>. It's free! (for moderate usage levels) See
<a href="https://docs.streamlit.io/cli.html#view-all-config-options">our documentation</a> for more
info on how to set config options.
`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the following snippet when I run streamlit config view:

[mapbox]

# Configure Streamlit to use a custom Mapbox token for elements like st.deck_gl_chart and st.map. If you don't do this you'll be using Streamlit's own token, which has limitations and is not guaranteed to always work. To get a token for yourself, create an account at https://mapbox.com. It's free! (for moderate usage levels)
# Default: ""
token = ""

I wonder if we need to change the comment in the config, because with these change the user will no longer be using Streamlit's own token unless they are running streamlit hello locally.

EDIT: I believe the config comments are at

_create_option(

Co-authored-by: Amey Deshpande <[email protected]>
@randyzwitch
Copy link
Copy Markdown
Contributor

randyzwitch commented Apr 30, 2020

I just realized, before we release this change we should sync with @randyzwitch on how to inform the community, and what changes we need to add for our docs.

Got it, ran into this same problem at my previous company, so familiar with the general idea.

I think we could make a forum post right away in Announcements to highlight our intentions; regardless of what implementation or deprecation decisions are being made, we've already decided that users in production must use their own key.

Once we think through the actual policy, then we can both update the Announcement forum page, as well as call it out in the changelog. I don't think we should necessarily worry about breaking old code after a 60-90 grace period; so throw a deprecation warning starting with the next release with a firm date in the message (July 31, 2020?), and then turn it off on the date we say in the deprecation warning.

@randyzwitch
Copy link
Copy Markdown
Contributor

If we want to be even more conservative, we could publish a blog post 30 days before we turn it off, to try and reach as many people as possible.

Copy link
Copy Markdown
Contributor

@tvst tvst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for at least one release before merging. Marking as "request changes" to block this in the meantime.

@tvst
Copy link
Copy Markdown
Contributor

tvst commented May 1, 2020

Given that this PR (and this issue) went through a thousand different specs/rewrites, I'd love to get it in "as is" rather than do more work on it.

With that in mind, how about we do the release like this:
(IIUC this is basically @randyzwitch's plan but with some dates tweaked)

  1. First do a forum post
  2. Wait N_MERGE weeks. Do normal releases throughout this time.
  3. Merge this code.
  4. Do a release. The release would behave this way:
    • Users on old Streamlit versions would not see any changes (they'd be using our old token, "token0")
    • Users on new Streamlit versions would not be able to use DeckGL maps without a token (the exception is hello.py, which would work by using "token1". This token only works on localhost, by the way)
  5. Wait N_FINAL_ANNOUNCE weeks.
  6. Make another announcement, this time saying old apps will stop working in N_DELETE weeks.
  7. Wait N_DELETE weeks.
  8. Delete token0.

From the eng side, it's best if N_MERGE is 2 weeks. As for N_FINAL_ANNOUNCE and N_DELETE, those don't matter to eng.

@randyzwitch would you be comfortable with this?

@tvst
Copy link
Copy Markdown
Contributor

tvst commented May 2, 2020

I found another problem.

Try this:
0) Make sure you don't have a Mapbox token configured

  1. streamlit hello
  2. Go to the map example
  3. Wait for the map to show up
  4. Go on your terminal (but don't close the browser tab!) and ctrl-c from the Streamlit server
  5. Now run streamlit run e2e/scripts/st_pydeck_chart.py

Expected: the charts should not show up. You should see 2 error messages instead.
Actual: you see two charts!

What's happening: the Mapbox token that was fetched with streamlit hello is hanging around in the tab, even if you change apps.

@tvst tvst mentioned this pull request May 2, 2020
@arraydude arraydude requested a review from tvst May 11, 2020 22:43
@tvst
Copy link
Copy Markdown
Contributor

tvst commented May 13, 2020

The backticks in the error are printing as actual backticks, not as inline <code>:

image

Also, when users have an st.map, the error mentions st.pydeck_chart rather than st.map. I think we can solve this by making the error mention both instead, like this:

To use st.pydeck_chart or st.map you need (...)

Copy link
Copy Markdown
Contributor

@tvst tvst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, check below

mkdir ~/.streamlit
MAPBOX_TOKEN=$(curl -sS https://data.streamlit.io/tokens.json | jq -r '.mapbox')
echo '[mapbox]' > ~/.streamlit/config.toml
echo 'token = "'$MAPBOX_TOKEN'"' >> ~/.streamlit/config.toml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a solution for local e2e tests too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the same for the dockerfile

@arraydude arraydude merged commit 0b633d2 into streamlit:develop May 27, 2020
@arraydude arraydude deleted the showingTokenErrorWhenNotLocalhost branch May 27, 2020 22:20
tconkling added a commit that referenced this pull request May 28, 2020
* develop:
  Enable WebSocket compression (#1506)
  Showing an error when it's not localhost and has no mapbox token (#1295)
  Reapply on_config_parsed after applying cli args (#1448)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Streamlit Mapbox API key

5 participants