Skip to content

Commit

Permalink
update docs to match developers site
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Oct 4, 2024
1 parent cdf4434 commit 585b642
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 24 deletions.
6 changes: 5 additions & 1 deletion docs/auth/connecting-to-a-portal.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ title: "Connect to your Portal"
uid: authenticating-with-r
---

```{r}
```

In order to create content, interact with non-public items, save geocoding results, or use POI data with the Places Service, you will need to authenticate through ArcGIS Online, ArcGIS Enterprise, or Platform.

:::{.callout-tip title="ArcGIS Sharing model" collapse="true"}
Items in ArcGIS Online and ArcGIS Enterprise can be unshared (accessible only to the item owner) or shared to groups, your organization, or everyone (![](../shared/images/sharing-public.png){width=30%}). [Learn more about Sharing here.](https://doc.arcgis.com/en/arcgis-online/share-maps/share-items.htm) Read and write access to an item is controlled by the owner-specified sharing level, organizational security settings, and the accessing user's [privileges](https://doc.arcgis.com/en/arcgis-online/administer/roles.htm).
Items in ArcGIS Online and ArcGIS Enterprise can be unshared (accessible only to the item owner) or shared to groups, your organization, or everyone (`r img("../shared/images/sharing-public.png", 50)`). [Learn more about Sharing here.](https://doc.arcgis.com/en/arcgis-online/share-maps/share-items.htm) Read and write access to an item is controlled by the owner-specified sharing level, organizational security settings, and the accessing user's [privileges](https://doc.arcgis.com/en/arcgis-online/administer/roles.htm).
:::


Expand Down
15 changes: 15 additions & 0 deletions docs/auth/connecting-to-a-portal_files/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"hash": "ec0de991bdf483a718483f14688bcada",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Connect to your Portal\"\nuid: authenticating-with-r\n---\n\n\n\n\nIn order to create content, interact with non-public items, save geocoding results, or use POI data with the Places Service, you will need to authenticate through ArcGIS Online, ArcGIS Enterprise, or Platform. \n\n:::{.callout-tip title=\"ArcGIS Sharing model\" collapse=\"true\"}\nItems in ArcGIS Online and ArcGIS Enterprise can be unshared (accessible only to the item owner) or shared to groups, your organization, or everyone (<span style=\"display:inline-block; width: 50%;\"><img src=\"../shared/images/sharing-public.png\" width=50%/></span>). [Learn more about Sharing here.](https://doc.arcgis.com/en/arcgis-online/share-maps/share-items.htm) Read and write access to an item is controlled by the owner-specified sharing level, organizational security settings, and the accessing user's [privileges](https://doc.arcgis.com/en/arcgis-online/administer/roles.htm).\n:::\n\n\n## Using OAuth2\n\nThere are two ways to authorize with [OAuth2](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/): either by using a a `code` or a `client` flow. Code-based authorization is interactive, requiring you to copy an authorization code from a browser window into the R console during the execution of your code. Client authorization allows for non-interactive scripting, but cannot be used for creating or modifying content. In most cases, code-based authorization is recommended. These two methods are explained below. \n\nBefore you can authorize with either OAuth2 method, you must first create a client ID. \n\n## Obtaining a Client ID\n\nIf a client ID is not provided to you by an administrator and you have the ability to create content items, you can create one. \n\nYou can do so by creating an application item. \n\n- Log in to your ArcGIS Online or ArcGIS Enterprise organization\n- Navigate to the Content tab\n- Click `New Item`\n- Select `Application` \n\n![](../shared/images/content-app.png){width=50%}\n\n- Choose `Other application` as your `Application Type`\n- Give the item an informative name such as `r-arcgis`\n - Optionally, specify the folder, tags, and summary as well.\n\n![](../shared/images/new-item.png){width=50%}\n\n- You will be directed to the item details page of the newly created application where you can see your credentials. **Do not share these**.\n\n![](../shared/images/credentials.png){width=50%}\n\n\n### Authorizing\n\nFirst, load the library. \n\n```r\nlibrary(arcgis)\n#> Attaching core arcgis packages:\n#> - {arcgisutils} v0.1.0\n#> - {arcgislayers} v0.1.0\n```\n\n#### Code flow\n\nThe OAuth2 Code Flow is a process where a user authorizes an application to act on their behalf by granting a temporary access token. This type of authorization permits the application to take actions on the user's behalf for the duration of the access token. Learn more about how [ArcGIS uses OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2/).\n\nRunning `auth_code()` will open a tab in your browser to begin the code flow. If you are authorizing to an ArcGIS Enterprise portal, ensure that you set the `ARCGIS_HOST` environment variable correctly and that you have restarted your R session. \n\n```r\ntoken <- auth_code()\n```\nYou will be prompted to sign in to your portal. \n\n![](../shared/images/oauth-sign-in.png){width=50%}\n\nOnce you've signed in, copy the code that appears, and return to R. Enter the code into the console without any modifications and press enter. \n\n![](../shared/images/oauth-code.png){width=70%}\n\nYour authorization will have completed. \n\n```r\ntoken\n#> <httr2_token>\n#> token_type: bearer\n#> access_token: <REDACTED>\n#> expires_at: 2023-03-03 13:21:40\n#> refresh_token: <REDACTED>\n#> username: your-user\n#> ssl: TRUE\n#> refresh_token_expires_in: 1209599\n```\n\n:::{.callout-warning}\nAuthorization tokens are temporary and will expire. If you encounter an invalid token error, you might need to generate a new token.\n:::\n\nTo make this token easily accessible to `{arcgis}`, use `set_arc_token()` which sets the token in dedicated authorization token environment.\n\n```r\nset_arc_token(token)\n```\n\n\n#### Client flow\n\nAlternatively, you can authorize using the client OAuth2 flow. This will authorize the application you created and not ourselves. Because of this, you cannot use the client flow to create or modify content. \n\nThe client flow has the benefit of being non-interactive, though. \n\n```r\ntoken <- auth_client()\nset_arc_token(token)\n```\n\n## Using a Named User\n\nAuthorizing using an ArcGIS Online or ArcGIS Enterprise [username and password](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/user-authentication/direct-username-password/) is a legacy method that is supported for cases where OAuth2 is not implemented. As a reminder, credentials should never be stored in plaintext in code.\n\n:::{.callout-important}\n**Security consideration**: Obtaining an access token with this method will expose the username and password credentials as plain text and could present a potential security risk.\n:::\n\n```r\ntoken <- auth_user(\n username = Sys.getenv(\"ARCGIS_USER\"),\n password = Sys.getenv(\"ARCGIS_PASSWORD\")\n host = arc_host(),\n expiration = 60\n)\nset_arc_token(token)\n```\n\n## Using `{arcgisbinding}`\n\nIf you are a user of ArcGIS Pro and have **arcgisbinding** installed, you can use `auth_binding()` to utilize the tokens that result from `arc.check_portal()`. `auth_binding()` has the benefit of being non-interactive _and_ authorizes you as a user. You can use `auth_binding()` for non-interactive work that creates or modifies existing content.\n\n```r\ntoken <- auth_binding()\nset_arc_token(token)\n```\n\nThis method retrieves the token from the *active* portal in ArcGIS Pro. Make sure that you are logged into the intended portal and that it is set as active. If you switch which portal is active in ArcGIS Pro, you will need to restart your R session for the new portal to be recognized by `auth_binding()`.\n\n\n## Using an API Key \n\nIf you are using ArcGIS Platform or using the ArcGIS Places Service, you will need to authorize via API key. Create an API key via the following instructions: \n\n* Navigate to https://developers.arcgis.com/\n* Sign in \n* Navigate to your API keys at https://developers.arcgis.com/api-keys/\n* Click `+ New API Key` & fill out the modal form\n\nStore the API key in your `.Renviron` file. You can call `usethis::edit_r_environ()` to open the file for you. \n\n```bash\nARCGIS_API_KEY=your-secret-api-key\n```\n\nRestart your R session for the key to be found. Next, load the `{arcgisutils}` package:\n\n```r\nlibrary(arcgisutils)\nauth_key()\n```",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
8 changes: 6 additions & 2 deletions docs/auth/storing-credentials.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Sys.getenv("ANSWER_TO_EVERYTHING")
Environment variables should _**never**_ be included in your code.
We recommend using an `.Renviron` file at minimum to store your credentials.

You can use the `usethis` package to edit the file. Ensure it is installed and run the following in your text editor:
You can use the [`usethis`](https://usethis.r-lib.org/) package to edit the file. Ensure it is installed and run the following in your text editor:

:::{.callout-warning}
If you modify environment variables you will need to restart your R session for the change to be registered.
Expand All @@ -48,17 +48,21 @@ usethis::edit_r_environ()
**User scoped** `.Renviron` files store environment variables in the user's home directory. The environment variables will be available to you in any project you open. However, if you share your project, the environment variables will not be shared with it.
:::

This will open your `.Renviron` file for you to edit.
This will open your `.Renviron` file for you to edit. The following are the environment variables used by `{arcgisutils}`.

```bash
# used for OAuth Code & Client
ARCGIS_CLIENT=your-client-id

# used for OAuth Client flow
ARCGIS_SECRET=your-super-secret-key

# used for publishing and Username/Password auth
ARCGIS_USER=your-user-name

# used for API Key auth
ARCGIS_API_KEY=your-developer-api-key

# specify if not using ArcGIS Online
ARCGIS_HOST=https://your-portal.com/
```
2 changes: 1 addition & 1 deletion docs/editing/add-features.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ We will go over the functions:

## Prerequisites

We will use the the *North Carolina SIDS* dataset we created in the [**Publishing from R**](/docs/layers/publishing.qmd) tutorial. To follow along, be sure that you have followed that tutorial and have a `FeatureLayer` that you can modify. If you have not yet configured your environment to authorize with an online portal, start at [**Connecting to your portal**](/docs/auth/connecting-to-a-portal.qmd).
We will use the the *North Carolina SIDS* dataset we created in the [**Publishing from R**](/layers/publishing) tutorial. To follow along, be sure that you have followed that tutorial and have a `FeatureLayer` that you can modify. If you have not yet configured your environment to authorize with an online portal, start at [**Connecting to your portal**](/authentication/connecting-to-a-portal).

## Adding features

Expand Down
4 changes: 2 additions & 2 deletions docs/editing/overview.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `{arcgislayers}` R package provides capabilities to add features, update the

## Important considerations

It is important to note that not everyone can edit an existing feature service. You must be an admin or an owner of the service that you want to edit. This requires that you have an account and can authorized yourself as a user.
It is important to note that not everyone can edit an existing feature service. You must be an admin or an owner of the service that you want to edit. This requires that you have an account and can authorize yourself as a user.

Additionally, fields cannot be added or deleted to an already existing feature service. If you wish to add or delete fields, you will need to publish a new layer.
Additionally, fields cannot be added or deleted to an already existing feature service. If you wish to add or delete fields, you will need to publish a new feature service.

10 changes: 6 additions & 4 deletions docs/editing/overwrite-features.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ knitr::opts_chunk$set(eval = FALSE)

From time to time as the owner of a Feature Layer, you may need to completely overwrite the data in the service. Overwriting a web layer from ArcGIS Pro may lead to a loss of associated pop-ups and symbology. One way to get around this is to truncate the feature service and append new data to the same service.

For this example, we need to be the owner of a Feature Service. As such, we will use the North Carolina SIDS dataset we created in the [**Publishing from R**](../layers/publishing.qmd) tutorial. If you have not done that tutorial, complete it first.
For this example, we need to be the owner of a Feature Service. As such, we will use the North Carolina SIDS dataset we created in the [**Publishing from R**](/layers/publishing) tutorial. If you have not done that tutorial, complete it first.

## Truncating a Feature Layer

Truncating a Feature Layer deletes every single record in the service and resets the auto-increment of the object ID. Truncating a service does not change the field definitions or permit us to add or remove fields. If you wish to do so, publish a new layer instead.

Before we can modify a service, we must first authorize ourselves with the portal. To do so we will use the `auth_code()` authorization flow. If you have not yet configured you environment to authorize with your portal, follow the [**Connecting to your Portal**](/docs/auth/connecting-to-a-portal.qmd) tutorial.
Before we can modify a service, we must first authorize ourselves with the portal. To do so we will use the `auth_code()` authorization flow. If you have not yet configured you environment to authorize with your portal, follow the [**Connecting to your Portal**](/authentication/connecting-to-a-portal) tutorial.

First load `arcgis`.

Expand All @@ -42,7 +42,7 @@ Token set to environment variable `ARCGIS_TOKEN`
Now that we have verified our identity with our portal we can create a `FeatureLayer` object in R from our hosted service. From your [content listing](https://arcgis.com/home/content.html) find the Feature Layer url.

:::{.callout-tip}
Revisit the "Obtaining a feature layer url" section of the [**Read hosted data**](/docs/layers/read-layers.qmd#obtaining-a-feature-layer-url) tutorial if you forgot how to retrieve the service url.
Revisit the "Obtaining a feature layer url" section of the [**Read hosted data**](/layers/read-layers) tutorial if you forgot how to retrieve the service url.
:::

```{r}
Expand Down Expand Up @@ -152,6 +152,8 @@ Capabilities: Create,Delete,Query,Update,Editing

If you view the hosted Feature Layer in the map viewer, you should now see the convex hulls.

![](../shared/images/nc-convex-hulls.png)
![](../shared/images/nc-sids.png)



![](../shared/images/nc-sids.png){width="10px"}
6 changes: 3 additions & 3 deletions docs/installation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ title: "Install and set up"
uid: installation
---

Before installing, we recommend that you have the newest version of R installed. At minimum, we sugest you use R version 4.3 or higher.
Before installing, we recommend that you have the newest version of R installed. At minimum, we sugest you use R version 4.3 or higher. You can install the latest version of R from [CRAN](https://cloud.r-project.org/).

## Installing `{arcgis}`

To install the `{arcgis}` location service metapackage, run the following from your console:

```r
install.packages("arcgis")
install.packages("arcgis", repos = c("https://r-arcgis.r-universe.dev", "https://cloud.r-project.org"))
```

Once the installation has finished you can load all of the packages using:
Expand Down Expand Up @@ -49,7 +49,7 @@ If you are working in ArcGIS Pro 2.0 or beyond, you have access to the built-in

:::{.callout-warning collapse="false"}

Note: All versions of R installed on your computer will appear in the drop-down menu. Make sure the version you select is R 3.2.2 or later. However, if you have installed R to a location other than the default, you might need to navigate to that location using the browse button.
Note: All versions of R installed on your computer will appear in the drop-down menu. It is recommended to use the newest vresion of R. If you have installed R to a location other than the default, you might need to navigate to that location using the browse button.

:::

Expand Down
2 changes: 1 addition & 1 deletion docs/layers/publishing.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In addition to consuming data as an R user, you may also want to publish data as
In order to publish content to ArcGIS Online or Enterprise, you must first obtain an access token permitting you to do so.

:::{.callout-caution}
If you have not yet set up your R environment for authorization, see [**Authorize with your Portal**](..//auth/connecting-to-a-portal.qmd). Ensure that the environment variables `ARCGIS_CLIENT` and `ARCGIS_USER` are set at minimum. If you are using ArcGIS Enterprise, ensure that `ARCGIS_HOST` is properly set as well.
If you have not yet set up your R environment for authorization, see [**Authorize with your Portal**](/authentication/connecting-to-a-portal). Ensure that the environment variables `ARCGIS_CLIENT` and `ARCGIS_USER` are set at minimum. If you are using ArcGIS Enterprise, ensure that `ARCGIS_HOST` is properly set as well.
:::

Go through the following code flow to set your credentials.
Expand Down
1 change: 0 additions & 1 deletion docs/layers/read-layers.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ The objective of this tutorial is to teach you how to:
- read in the data from the Feature Layer
- select the Feature Layer data by column
- filter the Feature Layer data by attributes
- use `dplyr` for selecting and filtering

## Obtaining a feature layer url

Expand Down
8 changes: 4 additions & 4 deletions docs/layers/read-rasters.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ Avoid reading in more data than you need! When extracting data from an image ser
```{r, message = FALSE}
crater <- arc_raster(
imgsrv,
xmin = "-846028",
ymin = "3373101",
xmax = "-833783",
ymax = "3380738"
xmin = -846028,
ymin = 3373101,
xmax = -833783,
ymax = 3380738
)
crater
```
Expand Down
8 changes: 5 additions & 3 deletions docs/places/overview.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ uid: places-overview

> The places service is a ready-to-use location service that can search for businesses and geographic locations around the world. It allows you to find, locate, and discover detailed information about each place.
In order to use `{arcgisplaces}` you will need an ArcGIS Developers account. [Get started here.](https://developers.arcgis.com/documentation/mapping-apis-and-services/get-started/)

In order to use `{arcgisplaces}` you will need an ArcGIS Developers account. [Get started here](https://developers.arcgis.com/documentation/mapping-apis-and-services/get-started/).


## Installation

`{arcgisplaces}` can be installed directly from CRAN using
`{arcgisplaces}` can be installed directly from R-universe using

```r
install.packages("arcgisplaces")
install.packages("arcgisplaces", repos = c("https://r-arcgis.r-universe.dev", "https://cloud.r-project.org"))
```

## Usage
Expand Down
4 changes: 2 additions & 2 deletions docs/system-requirements.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ The `{arcgis}` meta-package consists of many smaller R packages, each of these w

`{arcgisutils}` is built in part using Rust via [extendr](https://extendr.github.io/). We recommend installing a binary from the [R-universe](https://r-arcgis.r-universe.dev/) or CRAN.
```{r eval = FALSE}
install.packages("arcgis", repos = "https://r-arcgis.r-universe.dev")
install.packages("arcgis", repos = c("https://r-arcgis.r-universe.dev", "https://cloud.r-project.org"))
```
If you need to install from source, `rustc` must be available with a minimum version of 1.69. We encourage using the most recent version of `rustc`.
If you need to install from source, `rustc` must be available with a minimum version of 1.70. We encourage using the most recent version of rust.

:::{.callout-tip}
We recommend installing Rust via [`rustup`](https://rustup.rs/). If you are on Windows, you must add the Windows GNU target via `rustup target add x86_64-pc-windows-gnu`.
Expand Down

0 comments on commit 585b642

Please sign in to comment.