Skip to content

updating mapbox token #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- run:
name: build site and perform front-matter checks
command: |
echo ${mapbox_token} > .mapbox_token
rm -rf build
mkdir build
mkdir build/ggplot2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Session Data files
.RData

#mapbox dev token
.mapbox_token

# Example code in package build process
*-Ex.R

Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Imports:
forcats,
ggplot2,
haven,
listviewer,
hms,
httr,
jsonlite,
Expand Down
23 changes: 10 additions & 13 deletions r/2017-01-19-buttons.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ output:
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
```

```{r, echo = FALSE}
# Mapbox token for plotly | this one is for plot_mapbox figure
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")

# Setting mapbox token for R environment
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
```

### New to Plotly?

Plotly's R library is free and open source!<br>
Expand Down Expand Up @@ -336,11 +327,17 @@ Animations are currently only available in the [development package](https://plo

When adding buttons to Plotly charts, users have the option of styling the color, font, padding, and position of the buttons. The example below demostrates hot to apply different styling options. See all updatemenus styling attributes here: https://plot.ly/r/reference/#layout-updatemenus.

#### Mapbox Access Token

To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/r/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).

```{r}
library(plotly)

# make sure you have a Mapbox token https://www.mapbox.com/help/create-api-access-token/
# Sys.setenv('MAPBOX_TOKEN' = 'your mapbox token')
mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token

# Setting mapbox token for R environment
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

So I'm pretty sure that either this Sys.setenv line or the config(accesstoken = mapboxToken) line are required but not both, just like in Javascript. Can you please update these docs to use one or the other and actually document this behaviour in the mapbox-layers file?

Copy link
Contributor Author

@jdamiba jdamiba Jan 9, 2020

Choose a reason for hiding this comment

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

From testing in my local dev environment, it seems like Sys.setenv is not a valid way of passing the token.

Edit: this turns out to be the case only if using the plot_mapbox() call signature instead of the plot_ly call signature.


# read in wind turbines and farms data
df_wind = read.csv('data/2805.csv')
Expand Down Expand Up @@ -426,8 +423,8 @@ p <- plot_mapbox(df_sub, lat = ~lat_DD, lon = ~long_DD, mode = 'scattermapbox',
yanchor = "bottom",
x = 1,
y = 0,
buttons=list(dark,basic,satellite))))

buttons=list(dark,basic,satellite)))) %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))

p
```
Expand Down
36 changes: 18 additions & 18 deletions r/2017-02-27-scattermapbox.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ thumbnail: thumbnail/scatter-mapbox.jpg
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
```

```{r, echo = FALSE}
# Mapbox token for plotly | this one is for plot_mapbox figure
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")

# Setting mapbox token for R environment
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
```

### New to Plotly?

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

Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
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.

```{r}
library(plotly)
packageVersion('plotly')
```

### Mapbox Access Token

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/.

```{r}
library(plotly)
packageVersion('plotly')
```
To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/r/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).

### Basic Example

```{r}
library(plotly)

mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
Sys.setenv("MAPBOX_TOKEN" = mapboxToken) # for Orca


dat <- map_data("world", "canada") %>% group_by(group)

p <- plot_mapbox(dat, x = ~long, y = ~lat) %>%
Expand All @@ -64,7 +55,8 @@ p <- plot_mapbox(dat, x = ~long, y = ~lat) %>%
layout(mapbox = list(zoom = 0,
center = list(lat = ~median(lat),
lon = ~median(long))
))
)) %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))

p
```
Expand All @@ -74,6 +66,9 @@ p
```{r}
library(plotly)

mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
Sys.setenv("MAPBOX_TOKEN" = mapboxToken) # for Orca

df = read.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/meteorites_subset.csv')

p <- df %>%
Expand All @@ -88,7 +83,8 @@ p <- df %>%
font = list(size = 8)),
margin = list(l = 25, r = 25,
b = 25, t = 25,
pad = 2))
pad = 2)) %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))

p
```
Expand All @@ -99,6 +95,9 @@ p
library(plotly)
library(dplyr)

mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
Sys.setenv("MAPBOX_TOKEN" = mapboxToken) # for Orca

# airport locations
air <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')

Expand All @@ -125,7 +124,8 @@ p <- plot_mapbox(mode = 'scattermapbox') %>%
margin = list(l = 0, r = 0,
b = 0, t = 0,
pad = 0),
showlegend=FALSE)
showlegend=FALSE) %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))

p
```
Expand Down
27 changes: 6 additions & 21 deletions r/2017-04-12-county-level-choropleth.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ thumbnail: thumbnail/county-level-choropleth.jpg
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
```

```{r, echo = FALSE}
# Mapbox token for plotly | this one is for plot_mapbox figure
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")

# Setting mapbox token for R environment
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
```

### New to Plotly?

Plotly's R library is free and open source!<br>
Expand All @@ -43,7 +34,7 @@ packageVersion('plotly')

### Mapbox Access Token

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/.
To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/r/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).

### Creating Polygon Boundaries

Expand Down Expand Up @@ -147,19 +138,12 @@ p
```

### Add Polygon to Mapbox

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).

```{r, results = 'hide'}
library(plotly)

Sys.setenv('MAPBOX_TOKEN' = 'your_mapbox_token_here')
```


```{r}
library(plotly)

mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
Sys.setenv("MAPBOX_TOKEN" = mapboxToken) # for Orca

p <- cali_pop %>%
group_by(group) %>%
plot_mapbox(x = ~long, y = ~lat, color = ~pop_cat, colors = c('#ffeda0','#f03b20'),
Expand All @@ -179,7 +163,8 @@ p <- cali_pop %>%
zoom = 4,
center = list(lat = ~median(lat), lon = ~median(long))),
margin = list(l = 0, r = 0, b = 0, t = 0, pad = 0)
)
) %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))

p
```
21 changes: 10 additions & 11 deletions r/2018-06-22-sf.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ thumbnail: thumbnail/sf.jpg
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
```

```{r, echo = FALSE}
# Mapbox token for plotly | this one is for plot_mapbox figure
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")

# Setting mapbox token for R environment
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
```

### New to Plotly?

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

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.

### Basic sf
### Mapbox Access Token

To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/r/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).

### Basic sf

``` {r}
library(plotly)
Expand Down Expand Up @@ -81,14 +76,18 @@ Or `plot_mapbox`:
library(plotly)
library(sf)

mapboxToken <- paste(readLines("../.mapbox_token"), collapse="") # You need your own token
Sys.setenv("MAPBOX_TOKEN" = mapboxToken) # for Orca

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

p <- plot_mapbox(nc, split=~NAME) %>%
layout(
mapbox = list(
zoom = 6
)
)
) %>%
config(mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN"))

p
```
Expand Down
17 changes: 4 additions & 13 deletions r/2019-09-20-filled-area-on-mapbox.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ thumbnail: thumbnail/area.jpg
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
```

```{r, echo = FALSE}
# Mapbox token for plotly | this one is for plot_mapbox figure
mapboxToken <- paste("pk.eyJ1IjoicGxvdGx5bWFwYm94IiwiYSI6ImNqdnBvNDMyaT",
"AxYzkzeW5ubWdpZ2VjbmMifQ.TXcBE-xg9BFdV2ocecc_7g", sep = "")

# Setting mapbox token for R environment
Sys.setenv("MAPBOX_TOKEN" = mapboxToken)
```

### New to Plotly?

Plotly's R library is free and open source!<br>
Expand All @@ -41,10 +32,9 @@ Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-abov
library(plotly)
packageVersion('plotly')
```

### Mapbox Access Token

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).
To plot on Mapbox maps with Plotly you *may* need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/r/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).

### How to Show an Area on a Map

Expand All @@ -54,7 +44,8 @@ There are three different ways to show an area in a mapbox:
<li> Use [Scattermapbox](https://plot.ly/r/reference/#scattermapbox) trace and define the corresponding geojson</li>
<li> Use the new trace type: [Choroplethmapbox](https://plot.ly/r/mapbox-county-choropleth/) for mapbox cases, or [Choropleth](https://plot.ly/r/choropleth-maps/) trace for non-mapbox ones.</li>
</ol>
The following example uses `Scattermapbox` and sets `fill = 'toself'`

The following example uses the `Scattermapbox` trace and sets `fill = 'toself'`

```{r}
library(plotly)
Expand Down Expand Up @@ -102,7 +93,7 @@ p

### Use the Corresponding Geojson

The second way is using Scattermapbox trace with the corresponding geojson.
The second way is using the `scattermapbox` trace with the corresponding geojson.

```{r}
library(plotly)
Expand Down
Loading