13

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?

blacksite
  • 12,086
  • 10
  • 64
  • 109
  • Are you sure you have access to css and js files at that particular location? If you are deploying to a distant server where you have little control of, you might just as well link to an online resource or keep the files local to your project. – Roman Luštrik Feb 24 '16 at 14:11
  • I had read & write access for both of those files at that particular file path, and all the files are local. I'm just curious as to how shinyapps.io handles those paths. My `global.R` script (which I haven't yet made, but is in `script.R`) contains something like: `dat <- read.csv("data.csv",header=T)` , so I wonder if that's the issue. I'm deploying straight to shinyapps.io. – blacksite Feb 24 '16 at 14:16
  • That's my point. How certain can you be that those particular folder will be available to you on shinyapps.io? My guess would be very little (unless I'm missing something in your question?). Ergo, you need to make those files "local" or download them from the web. – Roman Luštrik Feb 25 '16 at 08:30

1 Answers1

13

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!

micstr
  • 5,080
  • 8
  • 48
  • 76
  • 1
    @blacksite can you elaborate which of the above points helped solving the problem? [Here](https://stackoverflow.com/questions/53152076/temp-files-automatically-deleted-in-r-shiny-app) is a related question. – ismirsehregal Aug 02 '19 at 06:48