It is good practice to not store API keys in code or as plain text!
To store API keys, we recommend using the keyring
package. This vignette provides a minimal intro to the necessary functionality. For further functionalities of keyring
, including real keyrings and password protection of the ChemSpider API key, we recommend the documentation of keyring
, available here.
Before proceeding, the package needs to be installed.
library("keyring")
keyring
The keyring::key_set()
will open a pop-up window in which the ChemSpider API key can be pasted in.
library(keyring) ## Note that Sys.getenv("USERNAME") is used to dynamically tie the API key to the current user. key_set(service = "ChemSpider API key", username = Sys.getenv("USERNAME"))
The name of the stored key is "ChemSpider API key", and the username is set to be the one currently operating R; this can of course be modified.
The stored API key can be accessed dynamically using the keyring::key_get()
function.
apikey <- key_get(service = "ChemSpider API key", username = Sys.getenv("USERNAME"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.