创建独立的Shiny App - Chrome错误 [英] Creating stand-alone Shiny App - Chrome Error

查看:292
本文介绍了创建独立的Shiny App - Chrome错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照这篇非常漂亮的博客文章的说明创建一个闪亮的桌面应用程序( http://www.r-bloggers.com/deploying-desktop-apps-with-r/

所以基本上我有一个具有以下结构的文件夹:

  App 
| __ GoogleChromePortable
| __ App
| __ Data
| __ ...
| __ R Portable
| __ App
| __ Data
| __ ...
| __ shiny
| __ ui.R
| __ server.R
| __ ...
| __ LAUNCH.bat / LAUNCH.vbs
| __ runShinyApp。 R

我正在创建2个不同的版本,一个使用GoogleChromePortable,另一个使用不带版本。这两个版本与 runShinyApp.R 中的Chrome路径完全相同。



runShinyApp.R

 #检查是否正确使用了正确的库路径)
message('library paths:\\\
',paste('...',.libPaths(),sep ='',collapse ='\\\
'))

#两个chromes的工作!
chrome.sys ='C:/ Program Files(x86)/Google/Chrome/Application/chrome.exe'
chrome.portable = file.path(getwd(),
'GoogleChromePortable /App/Chrome-bin/chrome.exe')

launch.browser = function(appUrl,browser.path = chrome.portable){
message('Browser path:',browser (''%s'--app =%s',browser.path,appUrl))
}
$ b $ shiny:runApp(' ./shiny/',launch.browser = launch.browser)

该应用程序通过 .bat .vbs 文件,这些文件基本上是相同的,但是第一个文件离开了Commander Prompt窗口。



LAUNCH.bat

  SET ROPTS =  -  no-save --no-environ --no-init-file --no-restore --no-Rconsole 
R-Portable \App\R- Portable \\\ Bin\Rscript.exe%ROPTS%runShinyApp.R 1> ShinyApp.log 2>& 1

LAUNCH.vbs $ b

  Rexe =R-Portable \App\R- Portable \bin\Rscript.exe 
Ropts =--no-save --no-environ --no-init-file --no-restore --no- Rconsole
RScriptFile =runShinyApp.R
Outfile =ShinyApp.log
strCommand = Rexe& & Ropts& & RScriptFile& 1>& Outfile& 2& 1

intWindowStyle = 0'隐藏窗口并激活另一个窗口'
bWaitOnReturn = False'启动后继续运行脚本R'

'以下是一个Sub调用,所以在参数'
CreateObject(Wscript.Shell)周围没有括号运行strCommand,intWindowStyle,bWaitOnReturn

问题:



我遇到的问题出现在两个版本中,如果我的系统上安装了正常的Chrome浏览器(不是便携式版本),那么闪亮的应用程序将毫无问题地启动。它会打开一个完全只包含闪亮应用程序的新窗口。



然而,如果我做的 没有打开Chrome会话(默认为一个)闪亮的版本似乎工作。一个窗口打开,但永远加载。
看看创建的日志,我得到以下错误:

  [4092:3596:0621/154834:ERROR :url_pattern_set.cc(240)]无效的网址格式:chrome:// print / * 
[4092:3596:0621/154834:错误:bluetooth_adapter_win.cc(102)]未实现

任何想法似乎都是这里的问题?

解决方案

我已经通过对 run.vbs 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'隐藏窗口并激活另一个窗口'
bWaitOnReturn = False'启动后继续运行脚本R'

'以下是一个Sub调用,所以在参数'

CreateObject(Wscript.Shell)附近不用括号。 .Run startChrome,intWindowStyle,bWaitOnReturn

我添加了 startChrome 变量并在之后调用 我启动服务器,因为否则没有网站,并且Chrome在以后启动时不会自动重新加载。通常启动服务器应该足够快,但是如果您使用的是非常慢的机器,则可能需要很长时间。然后,您需要在两个 CreateObject 调用之间添加延迟。



--app设置打开应用程序一个没有所有Google Chrome浏览器按钮的窗口,然后它看起来像一个独立应用程序。



runShinyApp.R:

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

Port 7777是任意的,您可以使用任何您喜欢的 free 端口。所有文件中的端口必须相同。



如果您想使用 bat 文件:

  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


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 basically I have a folder with the following structure:

App
|__ GoogleChromePortable
     |__ App
     |__ Data
     |__ ...
 |__ R Portable
     |__ App
     |__ Data
     |__ ...
|__ shiny
     |__ ui.R
     |__ server.R
     |__ ...
|__ LAUNCH.bat/LAUNCH.vbs
|__ runShinyApp.R

I am creating 2 different version, one with GoogleChromePortable and one without. Both versions are exactly the same apart from the path to Chrome in runShinyApp.R.

runShinyApp.R:

# checking if correct library paths are being used (only portable one!)
message('library paths:\n', paste('... ', .libPaths(), sep='',     collapse='\n'))

# both chromes work!
chrome.sys = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
chrome.portable = file.path(getwd(),
                        'GoogleChromePortable/App/Chrome-bin/chrome.exe')

launch.browser = function(appUrl, browser.path=chrome.portable) {
message('Browser path: ', browser.path)
shell(sprintf('"%s" --app=%s', browser.path, appUrl))
}

shiny::runApp('./shiny/', launch.browser=launch.browser)

The app is launched through a .bat or .vbs file which are basically the same but for the fact that the first leaves a Commander Prompt window open.

LAUNCH.bat:

SET ROPTS=--no-save --no-environ --no-init-file --no-restore --no-Rconsole
R-Portable\App\R-Portable\bin\Rscript.exe %ROPTS% runShinyApp.R 1> ShinyApp.log 2>&1

LAUNCH.vbs :

Rexe           = "R-Portable\App\R-Portable\bin\Rscript.exe"
Ropts          = "--no-save --no-environ --no-init-file --no-restore --no-   Rconsole"
RScriptFile    = "runShinyApp.R"
Outfile        = "ShinyApp.log" 
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

Issue:

The issue I am having is appearing in both versions and is the following.

IF I have my normal Chrome launched (NOT the portable version) installed on my system, the shiny app launches without any issues. It opens a new window entirely containing only the shiny app.

However IF I do not have a Chrome session open (default one), neither versions of the shiny seem to work. A window opens but loads forever. Looking at the created logs, I get the following error:

[4092:3596:0621/154834:ERROR:url_pattern_set.cc(240)] Invalid url pattern: chrome://print/*
[4092:3596:0621/154834:ERROR:bluetooth_adapter_win.cc(102)] NOT IMPLEMENTED

Any idea what seems to be the issue here?

解决方案

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

这篇关于创建独立的Shiny App - Chrome错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆