using directory as a variable

greetings everyone
I try to retrieve the current directory and then treat it as a variable that I can write to a file.

In the example I show below, the goal is slightly different but it reflects my shortcomings for this kind of task. Here, using the current directory to write a file.

library(shiny)

ui <- fluidPage(
  mainPanel(
    verbatimTextOutput("currentPathway", placeholder = TRUE)  
  ))

server <- function(input, output) {
  global <- reactiveValues(datapath = getwd())
  output$currentPathway <- renderText({global$datapath})

  tableFileName = paste(output$currentPathway, '/table.txt', sep='')
  write.table( matrix(1:10, ncol=2), tableFileName )
}

# Run the application
shinyApp(ui = ui, server = server)

Here, R refuses to paste output$currentPathway with '/table.txt'.
Would anyone by any chance know how to do that?
Thank you all very much,
C.

Does this do what you want?

library(shiny)

ui <- fluidPage(
  mainPanel(
    verbatimTextOutput("currentPathway", placeholder = TRUE)  
  ))

server <- function(input, output) {
  global <- reactiveValues(datapath = getwd())
  output$currentPathway <- renderText({global$datapath})
  
  observe({
    tableFileName = paste(global$datapath, '/table.txt', sep='')
    write.table( matrix(1:10, ncol=2), tableFileName )
  })
}

# Run the application
shinyApp(ui = ui, server = server)

It's excellent, thank you!

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