代码之家  ›  专栏  ›  技术社区  ›  Marin

运行Shining server时的特定R命令行选项

  •  1
  • Marin  · 技术社区  · 7 年前

    我在Ubuntu上运行闪亮服务器,我需要设置不同的R命令行选项——特别是 --max-ppsize . 我没有找到如何修改闪亮服务器的运行方式 R . 如何修改?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Artem Sokolov    7 年前

    中概述了使其发挥作用的关键 1.3.5 R Installation Location 闪亮服务器配置手册。主要思想是创建自己的可执行文件,名为 R 让它将您想要的命令行参数传递给 R 可执行文件。

    步骤1:创建新用户

    我给我的取名叫鲍勃。将以下文件添加到Bob的主目录。

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

    /home/bob/myR/R:

    #!/bin/bash
    /usr/bin/R --max-ppsize 123456 "$@"
    

    通过执行以下操作使第二个文件可执行 chmod +x /home/bob/myR/R .

    第2步:配置shiny以Bob的身份运行应用程序

    在Shining配置文件中,添加以下内容:

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

    运行时 testApp ,Shiny将首先找到Bob的 .bash_profile ,这使得 指向Bob的版本,因为 $PATH 优先Bob的版本只是添加了您想要的 --max-ppsize 并将其传递给real 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/Shining server/testApp/ui。R

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

    /srv/Shining 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