简体   繁体   English

将环境变量传递给 Shinyapps.io

[英]Passing environmental variables to shinyapps.io

I'm trying to publish a Shiny app to shinyapps.io but the app requires a Quandl API connection.我正在尝试将 Shiny 应用程序发布到 Shinyapps.io,但该应用程序需要 Quandl API 连接。 I don't want to put the API key in my code so I use a .Renviron file to store the API key.我不想将 API 密钥放在我的代码中,所以我使用.Renviron文件来存储 API 密钥。

This is the content of the .Renviron file:这是.Renviron文件的内容:

QUANDL_API_KEY=api_key_goes_here

This is the content of the .Rmd file:这是 .Rmd 文件的内容:

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

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

When I deploy to shinyapps.io nothing is printed out.当我部署到 Shinyapps.io 时,什么也没有打印出来。 But when I run locally, the key is printed.但是当我在本地运行时,会打印密钥。 The .Renviron file is in the app root directory. .Renviron文件位于应用程序根目录中。

What am I doing wrong?我究竟做错了什么?

As Bill Ash suggests in the comments, using readRenviron() at the beginning of the script worked for me:正如 Bill Ash 在评论中所建议的那样,在脚本开头使用readRenviron()对我readRenviron()

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM