错误:无法在 R Shiny 中打开连接 [英] ERROR: cannot open the connection in R Shiny

查看:33
本文介绍了错误:无法在 R Shiny 中打开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完成了此处的所有步骤,甚至收到了以下消息没有错误:

I went through all of the steps found here, and even got the following message without error:

Application successfully deployed to https://user-name.shinyapps.io/projectFolder/

但是,我在尝试运行程序时收到 ERROR: cannot open the connection 消息.以下是我将 R Studio 定向到的文件夹 (projectFolder) 的内容:

However, I get the ERROR: cannot open the connection message when trying to run the program. Here are the contents of the folder (projectFolder) to which I directed R Studio:

ui.R              # contains only ui code
server.R          # contains only server code
script.R          # my full script, which contains global, ui, and server code
gomap.js          # used for mapping app
styles.css        # used for Shiny App
data.csv          # my global data to be hosted on shinyapps.io

以下是不同脚本的示例:

Here's a sample of the different scripts:

ui.R

ui <- shinyUI(navbarPage("Tab title", id="nav",
                     tabPanel("Interactive map",
                              div(class="outer",

                                  tags$head(
                                    includeCSS("/Users/user/Documents/R/projects/styles.css"),
                                    includeScript("/Users/user/Documents/R/projects/gomap.js")
                                  ),
                                  #### more UI code ####
    )) 
))

问题可能是因为上面的文件路径吗?我需要在 ui.Rserver.R 文件的顶部设置 setwd 吗?或者是因为在 script.R 中你可以找到 ui.Rserver.R 的完整代码(也许这是多余的,我需要创建一个仅包含数据加载和操作的 global.R 文件?

Might the issue be because of the filepaths above? Do I need to setwd at the top of both the ui.R and server.R files? Or is it because within script.R you can find the full code for ui.R and server.R (perhaps this is redundant and I need to create a global.R file with just the data loading and manipulation?

首要问题是,您如何分解文件以加载到 Shinyapps.io 上?

The overarching question is, how do you break up your files to load onto shinyapps.io?

推荐答案

GBR24,有些事情你可以试试:

GBR24, some things you can try:

  1. 相对路径

根据 ui.R 文件和 server.r 文件的位置设置你的措辞目录,然后使用相对小写路径到你的子目录,如 css 部署时,不是完整的 \user\Me\MyR\Project1\ ...etc.

Set up your wording directory as to where your ui.R files and server.r files are and then use relative lowercase paths to your subdirectories like css when deploying, not full ones with \user\Me\MyR\Project1\ ...etc.

Path layout example:
directory with ui.r file which will be 
--css subdirectory
--data
--www

因此,当您调用放置在 data 子目录中的数据时,请使用:

so when you call your data that you have placed in data subdirectory use:

myfile <- file.path("data", "data.csv") 
dat <- read.csv(myfile, header=T)

  • 无大写

    这可能是文件名和路径大小写的问题.这才刚刚开始发生在我身上.在 RStudio 中部署时,我在发布带有 文件路径在部署服务器警告上区分大小写" 的内容时会收到一个审查问题对话框.

    This could be a problem with capitalisation of file names and paths. This has just started to happen to me. On deploying in RStudio I get a review issues dialogue when publishing content with a "filepaths are case-sensitive on deployment server warning".

    例如,Shiny 服务器需要 serverhead.R 而不是 serverHead.R.解决方案是将文件名更改为小写..R 扩展名现在大写似乎没问题.

    So, for example, Shiny server wants serverhead.R not serverHead.R. Solution is to change your file names to lowercase. It seems to be okay with .R extension capitalised for now.

    github windows 用户:你需要提醒 Github 你需要小写,这样它不会用 CaseNotLowered.R

    github windows users: You need to remind Github that you want lowercase so it does not push files back with CaseNotLowered.R

    在 Gitshell 中,您强制使用文件名:

    In Gitshell, you force the file name:

    git mv -f OldName newname
    

    感谢 Github 支持 以及这里的答案.

    Thanks to Github Support and answers here.

    查看日志

    您可以使用此命令从 RStudio 检查您的部署以获取线索.从控制台命令行,使用您的帐户和应用名称:

    You can check on your deployment from RStudio using this command for clues. From console command line, with your account and app name:

    rsconnect::showLogs(account = "myshinyioaccount", appName = "myapp")
    

    编辑它以前是 shinyapps::showLogs(感谢 conrad-mac)

    EDIT it was formerly shinyapps::showLogs (thanks conrad-mac)

    例如,我可以在连接错误消息之前看到文件名问题:

    For example I could see a filename problem before the connection error message:

    ... 2016-07-12T13:13:26.061123+00:00 Shinyapps[555]:文件错误(文件名,r",编码 = 编码):

    ... 2016-07-12T13:13:26.061123+00:00 shinyapps[555]: Error in file(filename, "r", encoding = encoding) :

    2016-07-12T13:13:26.060971+00:00 Shinyapps[555]: 2: eval.parent

    2016-07-12T13:13:26.060971+00:00 shinyapps[555]: 2: eval.parent

    2016-07-12T13:13:26.061126+00:00 Shinyapps[555]:无法打开连接

    2016-07-12T13:13:26.061126+00:00 shinyapps[555]: cannot open the connection

  • 希望这会有所帮助!

    这篇关于错误:无法在 R Shiny 中打开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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