2017-10-16 176 views

回答

1

使用Shiny Server配置手冊的1.3.5 R Installation Location中列出了實現此功能的關鍵。主要想法是創建自己的可執行文件,命名爲R,並讓它將命令行參數傳遞給您想要的可執行文件的真實R

第1步:創建一個新用戶

我將其命名鮑勃。將以下文件添加到Bob的主目錄中。

/home/bob/.bash_profile:

export PATH=/home/bob/myR:$PATH 

/首頁/鮑勃/ MYR/R:

#!/bin/bash 
/usr/bin/R --max-ppsize 123456 "[email protected]" 

chmod +x /home/bob/myR/R使第二個文件的可執行文件。

步驟2:配置閃亮運行你的應用程序作爲鮑勃

在你閃亮的配置文件,添加以下內容:

location /testApp { 
    run_as bob; 
    site_dir /srv/shiny-server/testApp; 
    log_dir /var/log/shiny-server; 
} 

當運行testApp,閃亮首先將源Bob的.bash_profile,這使得R指向Bob的版本,因爲$PATH優先。鮑勃的版本只需添加您所需的--max-ppsize選項,並將其與其他選項"[email protected]"一起傳遞給實際的R可執行文件。你可以自己進行測試,這樣做:

$ su bob 
$ source /home/bob/.bash_profile 
$ which R 
/home/bob/myR/R 
$ R -q --args Test 
> commandArgs() 
[1] "/usr/lib/R/bin/exec/R" "--max-ppsize"   "123456" 
[4] "-q"     "--args"    "Test" 

第3步:創建一個testApp,以確保一切都正在按預期運行

這裏是我的測試閃亮的應用程序。

/srv/shiny-server/testApp/ui.R

ui <- fluidPage(
    textOutput("user"), 
    textOutput("cmdArgs") 
) 

/srv/shiny-server/testApp/server.R

server <- function(input, output, session) 
{ 
    output$user <- renderText({ 
    Sys.info()["user"] 
    }) 

    output$cmdArgs <- renderText({ 
    paste(commandArgs(), collapse=" ") 
    }) 
} 

結果在Firefox:

enter image description here