Where would be the location of my project when running in R studio connect server

Hi all,

I have a concern here. Below is simple application. When I run this code, I get location of my project in my R console (since I have print(getwd()) at the last line). But when I deploy this in my Rstudio connect server or shinyapps.io. When can I see this location. In fact it will no more be my local system. So I have 2 questions here

  1. What would be my location (getwd()) when I deploy this application to RStudio connect server or Shinyapps,io
  2. Where can I see this print?

Can you please make me understand.

ui.R

library(shiny)


# Define UI for application that draws a histogram
shinyUI(fluidPage(
  
  textInput("name", "Name: "),
  textOutput("greeting"),
  selectInput("Slider","Slider",choices = unique(iris$Species))
  )
  )

server.R

library(shiny)

shinyServer(function(input, output) {
  
  output$greeting <- renderText({
    paste0("Hello, ", input$name, "!")
  })
  print(getwd())
  })

shinyapps.io has a log, which you can access/download from the dashboard.
Also while debugging your project you could have a textoutput that gives you that info

output$greeting <- renderText({
    paste0("Hello, ", input$name, "! the working directory is ", getwd())
  })
``
Finally, if you can connect your shiny app to some backend, like a database, you could write your console outputs to that...

However, in the specific case where you are interested in working directory and not necessarily logging. it should be that theres not any reason for you to know the file space on shinyapps.io. you can find your own data using relative path from whatever your getwd() might be. file.path() function is recommended for constructing paths, you can make the first parameter you pass in to be getwd(), so you can use the working directory without 'knowing what it is'

Hope something here helps.

HI Nir, Thanks for the time

Sorry may be I did not understand your solutions.

Can you guide me here. When I deploy this in Rstudio connect server how can I access my log or download my log?

The reason why I gave this example, is I have something in mind, that is I want to create a empty file file.create("test.txt") . So I am planning to put this code in my server.R file. SAmple below. Hope this makes more sense. In short it would be helpful if you could let me know where and how can i access this empty file in my Rstudio connect server

server.R

library(shiny)


# Define server logic required to draw a histogram
shinyServer(function(input, output) {
  
  output$greeting <- renderText({
    paste0("Hello, ", input$name, "!")
  })
  # print(getwd()) 
  file.create("test1.txt") # I am creating a file. But where this would be located when I deploy this in RStudio connect server
  })

The dashboard looks like this :


when you choose your app:

you can see if your file exists in the wd() once you made it like this:

shinyServer(function(input, output) {
  myfilexists <- eventReactive(input$checkme,{
file.exists("test1.txt")
})
  output$greeting <- renderText({
    paste0("Hello, ", input$name, " Does your file exist ?", myfileexists())
  })
  # print(getwd()) 
  file.create("test1.txt") # I am creating a file. But where this would be located when I deploy this in RStudio connect server
  })

add an actionbutton to your ui called "checkme". then when you click it it will update myfileexists() and update the greeting.

Oh that is awesome Nir. Thanks a lot for your time and tons of appreciation for you. Will check it. Hope this same logic is for Rstudio connect server as well?

Hi Nir,

Hope you are enjoying weekend. Perfect it is working and I get true when I click the button. But when see logs, I am not able to see that file. Let us say, I have something in the file and I need to access it. Wanted to check if it be done?

Maybe you could put here an example of what you want to do with the file forget the shiny part.
You want to print to console/log that you checked file existed and it does or doesn't?
You want to read what's in the file and use it for something?

Hi Nir, Thanks. I got it working in connect server as well. You solution was very good actually. But i am facing a challenging issue here. (i have posted as another question below)

Basically I need to run app <- shinyDriver$new(getwd()) in my R studio connect server. But not able to. Application is crashing. I can this code in my local machine. But really suprised as to why I cannot run app <- shinyDriver$new(getwd()) when I deploy my application in my Rstudio connect server. It would be really helpful if you can guide me in this :slight_smile:

Hi Vinay, I wish you luck but I didn't study shinydriver yet.

Thanks for the efforts anyways :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.