0

I have a sample application where it creates a dummy text file in the working directory. Now I have another R file(add.R) where I need to execute it and paste the results in a text file. Below is the reprex

ui.R

library(shiny)
source("add.R")


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

server.R

library(shiny)
source("add.R")


# Define server logic required to draw a histogram
shinyServer(function(input, output) {
  myfileexists <- eventReactive(input$checkme,{
    file.exists("test2.txt")  
    })
  output$greeting <- renderText({
    paste0("Hello, ", input$name, "Does your file exist ?", myfileexists())
  })
  print(getwd())
  file.create("test2.txt")
  })
  

add.R

a <- 3 + 4
b <- 3 + t

Expected out put. IN case any error, the application should show error occurred

text2.txt file

a <- 3 + 4

a

[1] 7

b <- 3 + t

Error in 3 + t : non-numeric argument to binary operator

Community
  • 1
  • 1
imran p
  • 332
  • 2
  • 12
  • 4
    That's a side-effect of choosing a single-letter variable name in a not-very-reproducible environment, when the variable name also happens to be a base R function, for `t`ranspose. If `t` were not defined and not a function, I would expect `Error: object 't' not found`, but instead you got that error. Try with another *function*, as in `3+paste`, and you'll get your error. Overall, this tells me either you have a typo; you are not managing your variable scope; or you are expecting non-literal programming (symbolic/non-standard stuff?). – r2evans Mar 01 '20 at 06:03
  • I agree with you. Overall my question was different :) It is actually is there a way to Execute a file in the working directory and paste the results in a text file – imran p Mar 01 '20 at 08:59
  • 1
    Define "execute file". You can always write to text file [by appending](https://stackoverflow.com/questions/7741575/add-lines-to-a-file). – Roman Luštrik Mar 01 '20 at 10:06
  • Do you mean `source` the file? – r2evans Mar 01 '20 at 14:39

0 Answers0