Creating stand-alone Shiny App - Chrome Error

前端 未结 2 1496
离开以前
离开以前 2020-12-30 09:26

I am trying to create a shiny desktop app following the instruction of this very nice blog post (http://www.r-bloggers.com/deploying-desktop-apps-with-r/)

So basica

2条回答
  •  轮回少年
    2020-12-30 10:09

    I have solved it that way with a few changes to run.vbs and runShinyApp.R.

    run.vbs:

    Rexe           = "R-Portable\App\R-Portable\bin\R.exe CMD BATCH"
    Ropts          = "--no-save --no-environ --no-init-file --no-restore --no-Rconsole "
    RScriptFile    = "runShinyApp.R"
    Outfile        = "ShinyApp.log"
    startChrome    = "GoogleChromePortable\Chrome\chrome.exe --app=http://127.0.0.1:7777"
    strCommand     = Rexe & " " & Ropts & " " & RScriptFile & " 1> " & Outfile & " 2>&1"
    
    intWindowStyle = 0     ' Hide the window and activate another window.'
    bWaitOnReturn  = False ' continue running script after launching R   '
    
    ' the following is a Sub call, so no parentheses around arguments'
    
    CreateObject("Wscript.Shell").Run strCommand, intWindowStyle, bWaitOnReturn
    CreateObject("Wscript.Shell").Run startChrome, intWindowStyle, bWaitOnReturn
    

    I added the startChrome variable and call CreateObject after I start the server, because otherwise there is no website and Chrome does not automatically reload when you start it afterwards. Usually starting the server should be fast enough but if you are on a very slow machine it might take too long. Then you need to add a delay between the two CreateObject calls.

    The --app setting opens the app in a window that does not have all the Google Chrome buttons and then it really looks like a standalone app.

    runShinyApp.R:

    require(shiny)
    shiny::runApp('./shiny/',port=7777)
    

    Port 7777 is arbitrary, you can use any free port you like. The port has to be same in all files.

    In case you want to use a bat file:

    SET ROPTS=--no-save --no-environ --no-init-file --no-restore --no-Rconsole
    start /b GoogleChromePortable\Chrome\chrome.exe --app=http://127.0.0.1:7777
    R-Portable\App\R-Portable\bin\R.exe CMD BATCH %ROPTS% runShinyApp.R 1> ShinyAppOut.log 2> ShinyAppMsg.log
    

提交回复
热议问题