Skip to content

Commit 603b870

Browse files
author
Joseph Damiba
committed
updating token
remove mapbox token from ci using correct attribute name for mapbox token moving access token paragraph to top of mapbox-layers example re-adding token to examples that need it
1 parent d5d56db commit 603b870

10 files changed

+100
-134
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
- run:
4040
name: build site and perform front-matter checks
4141
command: |
42+
echo ${mapbox_token} > .mapbox_token
4243
rm -rf build
4344
mkdir build
4445
mkdir build/ggplot2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Session Data files
66
.RData
77

8+
#mapbox dev token
9+
.mapbox_token
10+
811
# Example code in package build process
912
*-Ex.R
1013

r/2017-01-19-buttons.Rmd

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ output:
1717
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
1818
```
1919

20-
```{r, echo = FALSE}
21-
# Mapbox token for plotly | this one is for plot_mapbox figure
22-
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
23-
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")
24-
25-
# Setting mapbox token for R environment
26-
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
27-
```
28-
2920
### New to Plotly?
3021

3122
Plotly's R library is free and open source!<br>
@@ -339,8 +330,10 @@ When adding buttons to Plotly charts, users have the option of styling the color
339330
```{r}
340331
library(plotly)
341332
342-
# make sure you have a Mapbox token https://www.mapbox.com/help/create-api-access-token/
343-
# Sys.setenv('MAPBOX_TOKEN' = 'your mapbox token')
333+
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
334+
335+
# Setting mapbox token for R environment
336+
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
344337
345338
# read in wind turbines and farms data
346339
df_wind = read.csv('data/2805.csv')
@@ -426,8 +419,8 @@ p <- plot_mapbox(df_sub, lat = ~lat_DD, lon = ~long_DD, mode = 'scattermapbox',
426419
yanchor = "bottom",
427420
x = 1,
428421
y = 0,
429-
buttons=list(dark,basic,satellite))))
430-
422+
buttons=list(dark,basic,satellite)))) %>%
423+
config(accesstoken = mapboxToken)
431424
432425
p
433426
```

r/2017-02-27-scattermapbox.Rmd

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ thumbnail: thumbnail/scatter-mapbox.jpg
1717
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
1818
```
1919

20-
```{r, echo = FALSE}
21-
# Mapbox token for plotly | this one is for plot_mapbox figure
22-
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
23-
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")
24-
25-
# Setting mapbox token for R environment
26-
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
27-
```
28-
2920
### New to Plotly?
3021

3122
Plotly's R library is free and open source!<br>
@@ -37,25 +28,37 @@ We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-docume
3728

3829
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
3930
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
31+
4032
```{r}
4133
library(plotly)
4234
packageVersion('plotly')
4335
```
4436

45-
### Mapbox Access Token
37+
### Mapbox Access Tokens and When You Need Them
4638

47-
To create mapbox maps with Plotly, you'll need a Mapbox account and a [Mapbox Access Token](https://www.mapbox.com/studio/) that you can add to your [Plotly Settings](https://plot.ly/settings/mapbox). If you're using a Chart Studio Enterprise server, please see additional instructions here: https://help.plot.ly/mapbox-atlas/.
48-
49-
```{r}
50-
library(plotly)
51-
packageVersion('plotly')
52-
```
39+
The word "mapbox" in the trace names and `layout.mapbox` refers to the Mapbox.js open-source library. If your basemap in `layout.mapbox.style` uses data from the Mapbox *service*, then you will need to register for a free account at https://mapbox.com/ and obtain a Mapbox Access token. This token should be provided either in `mapboxAccessToken` in `setPlotConfig` function, or as a variable that would be passed as an argument of `newPlot`.
40+
If your `layout.mapbox.style` does not use data from the Mapbox service, you do *not* need to register for a Mapbox account.
41+
<h6>Base Maps in `layout.mapbox.style`</h6>
42+
The accepted values for `layout.mapbox.style` are one of the following tiles.
43+
<ol>
44+
<li> `"white-bg"` yields an empty white canvas which results in no external HTTP requests </li>
45+
<li> `"open-street-map"`, `"carto-positron"`, `"carto-darkmatter"`, `"stamen-terrain"`, `"stamen-toner"` or `"stamen-watercolor"` yeild maps composed of *raster* tiles from various public tile servers which do not require signups or access tokens </li>
46+
<li> `"basic"`, `"streets"`, `"outdoors"`, `"light"`, `"dark"`, `"satellite"`, or `"satellite-streets"` yeild maps composed of *vector* tiles from the Mapbox service, and *do* require a Mapbox Access Token or an on-premise Mapbox installation. </li>
47+
<li> A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation. </li>
48+
<li> A Mapbox Style object as defined at https://docs.mapbox.com/mapbox-gl-js/style-spec/ </li>
49+
</ol>
5350

5451
### Basic Example
5552

5653
```{r}
5754
library(plotly)
5855
56+
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
57+
58+
# Setting mapbox token for R environment
59+
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
60+
61+
5962
dat <- map_data("world", "canada") %>% group_by(group)
6063
6164
p <- plot_mapbox(dat, x = ~long, y = ~lat) %>%
@@ -64,7 +67,8 @@ p <- plot_mapbox(dat, x = ~long, y = ~lat) %>%
6467
layout(mapbox = list(zoom = 0,
6568
center = list(lat = ~median(lat),
6669
lon = ~median(long))
67-
))
70+
)) %>%
71+
config(mapboxAccessToken = mapboxToken)
6872
6973
p
7074
```
@@ -74,6 +78,11 @@ p
7478
```{r}
7579
library(plotly)
7680
81+
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
82+
83+
# Setting mapbox token for R environment
84+
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
85+
7786
df = read.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/meteorites_subset.csv')
7887
7988
p <- df %>%
@@ -88,7 +97,8 @@ p <- df %>%
8897
font = list(size = 8)),
8998
margin = list(l = 25, r = 25,
9099
b = 25, t = 25,
91-
pad = 2))
100+
pad = 2)) %>%
101+
config(mapboxAccessToken = mapboxToken)
92102
93103
p
94104
```
@@ -99,6 +109,11 @@ p
99109
library(plotly)
100110
library(dplyr)
101111
112+
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
113+
114+
# Setting mapbox token for R environment
115+
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
116+
102117
# airport locations
103118
air <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
104119
@@ -125,7 +140,8 @@ p <- plot_mapbox(mode = 'scattermapbox') %>%
125140
margin = list(l = 0, r = 0,
126141
b = 0, t = 0,
127142
pad = 0),
128-
showlegend=FALSE)
143+
showlegend=FALSE) %>%
144+
config(mapboxAccessToken = mapboxToken)
129145
130146
p
131147
```

r/2017-04-12-county-level-choropleth.Rmd

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ thumbnail: thumbnail/county-level-choropleth.jpg
1616
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
1717
```
1818

19-
```{r, echo = FALSE}
20-
# Mapbox token for plotly | this one is for plot_mapbox figure
21-
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
22-
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")
23-
24-
# Setting mapbox token for R environment
25-
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
26-
```
27-
2819
### New to Plotly?
2920

3021
Plotly's R library is free and open source!<br>
@@ -41,9 +32,19 @@ library(plotly)
4132
packageVersion('plotly')
4233
```
4334

44-
### Mapbox Access Token
35+
### Mapbox Access Tokens and When You Need Them
4536

46-
To create mapbox maps with Plotly, you'll need a Mapbox account and a [Mapbox Access Token](https://www.mapbox.com/studio/) that you can add to your [Plotly Settings](https://plot.ly/settings/mapbox). If you're using a Chart Studio Enterprise server, please see additional instructions here: https://help.plot.ly/mapbox-atlas/.
37+
The word "mapbox" in the trace names and `layout.mapbox` refers to the Mapbox.js open-source library. If your basemap in `layout.mapbox.style` uses data from the Mapbox *service*, then you will need to register for a free account at https://mapbox.com/ and obtain a Mapbox Access token. This token should be provided either in `mapboxAccessToken` in `setPlotConfig` function, or as a variable that would be passed as an argument of `newPlot`.
38+
If your `layout.mapbox.style` does not use data from the Mapbox service, you do *not* need to register for a Mapbox account.
39+
<h6>Base Maps in `layout.mapbox.style`</h6>
40+
The accepted values for `layout.mapbox.style` are one of the following tiles.
41+
<ol>
42+
<li> `"white-bg"` yields an empty white canvas which results in no external HTTP requests </li>
43+
<li> `"open-street-map"`, `"carto-positron"`, `"carto-darkmatter"`, `"stamen-terrain"`, `"stamen-toner"` or `"stamen-watercolor"` yeild maps composed of *raster* tiles from various public tile servers which do not require signups or access tokens </li>
44+
<li> `"basic"`, `"streets"`, `"outdoors"`, `"light"`, `"dark"`, `"satellite"`, or `"satellite-streets"` yeild maps composed of *vector* tiles from the Mapbox service, and *do* require a Mapbox Access Token or an on-premise Mapbox installation. </li>
45+
<li> A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation. </li>
46+
<li> A Mapbox Style object as defined at https://docs.mapbox.com/mapbox-gl-js/style-spec/ </li>
47+
</ol>
4748

4849
### Creating Polygon Boundaries
4950

@@ -147,18 +148,13 @@ p
147148
```
148149

149150
### Add Polygon to Mapbox
150-
151-
To create mapbox maps with Plotly, you'll need a Mapbox account and a [Mapbox Access Token](https://www.mapbox.com/studio/) that you can add to your [Plotly Settings](https://plot.ly/settings/mapbox).
152-
153-
```{r, results = 'hide'}
151+
```{r}
154152
library(plotly)
155153
156-
Sys.setenv('MAPBOX_TOKEN' = 'your_mapbox_token_here')
157-
```
158-
154+
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
159155
160-
```{r}
161-
library(plotly)
156+
# Setting mapbox token for R environment
157+
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
162158
163159
p <- cali_pop %>%
164160
group_by(group) %>%
@@ -179,7 +175,8 @@ p <- cali_pop %>%
179175
zoom = 4,
180176
center = list(lat = ~median(lat), lon = ~median(long))),
181177
margin = list(l = 0, r = 0, b = 0, t = 0, pad = 0)
182-
)
178+
) %>%
179+
config(mapboxAccessToken = mapboxToken)
183180
184181
p
185182
```

r/2018-06-22-sf.Rmd

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ thumbnail: thumbnail/sf.jpg
1616
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
1717
```
1818

19-
```{r, echo = FALSE}
20-
# Mapbox token for plotly | this one is for plot_mapbox figure
21-
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
22-
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")
23-
24-
# Setting mapbox token for R environment
25-
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
26-
```
27-
2819
### New to Plotly?
2920

3021
Plotly's R library is free and open source!<br>
@@ -49,6 +40,20 @@ In order to complete the examples below, you'll require installing additional pa
4940

5041
The examples below use the library [simple features](https://r-spatial.github.io/sf/) to read in the shape files before plotting the features with Plotly.
5142

43+
### Mapbox Access Tokens and When You Need Them
44+
45+
The word "mapbox" in the trace names and `layout.mapbox` refers to the Mapbox.js open-source library. If your basemap in `layout.mapbox.style` uses data from the Mapbox *service*, then you will need to register for a free account at https://mapbox.com/ and obtain a Mapbox Access token. This token should be provided either in `mapboxAccessToken` in `setPlotConfig` function, or as a variable that would be passed as an argument of `newPlot`.
46+
If your `layout.mapbox.style` does not use data from the Mapbox service, you do *not* need to register for a Mapbox account.
47+
<h6>Base Maps in `layout.mapbox.style`</h6>
48+
The accepted values for `layout.mapbox.style` are one of the following tiles.
49+
<ol>
50+
<li> `"white-bg"` yields an empty white canvas which results in no external HTTP requests </li>
51+
<li> `"open-street-map"`, `"carto-positron"`, `"carto-darkmatter"`, `"stamen-terrain"`, `"stamen-toner"` or `"stamen-watercolor"` yeild maps composed of *raster* tiles from various public tile servers which do not require signups or access tokens </li>
52+
<li> `"basic"`, `"streets"`, `"outdoors"`, `"light"`, `"dark"`, `"satellite"`, or `"satellite-streets"` yeild maps composed of *vector* tiles from the Mapbox service, and *do* require a Mapbox Access Token or an on-premise Mapbox installation. </li>
53+
<li> A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation. </li>
54+
<li> A Mapbox Style object as defined at https://docs.mapbox.com/mapbox-gl-js/style-spec/ </li>
55+
</ol>
56+
5257
### Basic sf
5358

5459
``` {r}
@@ -81,14 +86,20 @@ Or `plot_mapbox`:
8186
library(plotly)
8287
library(sf)
8388
89+
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
90+
91+
# Setting mapbox token for R environment
92+
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
93+
8494
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
8595
8696
p <- plot_mapbox(nc, split=~NAME) %>%
8797
layout(
8898
mapbox = list(
8999
zoom = 6
90100
)
91-
)
101+
) %>%
102+
config(mapboxAccessToken = mapboxToken)
92103
93104
p
94105
```

r/2019-09-20-filled-area-on-mapbox.Rmd

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ thumbnail: thumbnail/area.jpg
1717
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
1818
```
1919

20-
```{r, echo = FALSE}
21-
# Mapbox token for plotly | this one is for plot_mapbox figure
22-
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
23-
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")
24-
25-
# Setting mapbox token for R environment
26-
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
27-
```
28-
2920
### New to Plotly?
3021

3122
Plotly's R library is free and open source!<br>
@@ -42,10 +33,6 @@ library(plotly)
4233
packageVersion('plotly')
4334
```
4435

45-
### Mapbox Access Token
46-
47-
To plot on Mapbox maps with Plotly you `may` need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio), that you can add to your [Plotly Settings](https://plot.ly/settings/mapbox). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information. If you're using a Chart Studio Enterprise server, please see additional instructions [here](https://help.plot.ly/mapbox-atlas).
48-
4936
### How to Show an Area on a Map
5037

5138
There are three different ways to show an area in a mapbox:

0 commit comments

Comments
 (0)