Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing environmental variables to shinyapps.io

Tags:

r

rstudio

shiny

I'm trying to publish a Shiny app to shinyapps.io but the app requires a Quandl API connection. I don't want to put the API key in my code so I use a .Renviron file to store the API key.

This is the content of the .Renviron file:

QUANDL_API_KEY=api_key_goes_here

This is the content of the .Rmd file:

---
title: "Test"
runtime: shiny
output: html_document
---

```{r}
print(Sys.getenv("QUANDL_API_KEY"))
```

When I deploy to shinyapps.io nothing is printed out. But when I run locally, the key is printed. The .Renviron file is in the app root directory.

What am I doing wrong?

like image 624
Giovanni Colitti Avatar asked Dec 13 '25 04:12

Giovanni Colitti


1 Answers

As Bill Ash suggests in the comments, using readRenviron() at the beginning of the script worked for me:

---
title: "Test"
runtime: shiny
output: html_document
---

```{r}
readRenviron(".Renviron")
print(Sys.getenv("QUANDL_API_KEY"))
```
like image 119
Giovanni Colitti Avatar answered Dec 15 '25 19:12

Giovanni Colitti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!