Execute a file in the working directory and paste the results in a text file

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

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