Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: cannot open the connection in 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/

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 ####
    )) 
))

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?

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

like image 860
blacksite Avatar asked Feb 24 '16 14:02

blacksite


1 Answers

GBR24, some things you can try:

  1. Relative Paths

    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
    

    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)
    
  2. NO CAPS

    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".

    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 users: You need to remind Github that you want lowercase so it does not push files back with CaseNotLowered.R

    In Gitshell, you force the file name:

    git mv -f OldName newname
    

    Thanks to Github Support and answers here.

  3. Look at logs

    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")
    

    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]: 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.061126+00:00 shinyapps[555]: cannot open the connection

Hope this helps!

like image 151
micstr Avatar answered Sep 27 '22 16:09

micstr