I have a R function that exports data, write up non-R script (like Python but not limited to), run the said script, then import the resulting data. For sake of simplicity, let's say it's batch and csv. I was hoping to transition this dummy function below into RShiny.
myscript <- "START START"
mydata <- head(cars)
###start of function, such as dummyfun(mydata, myscript)###
write.table(myscript, "notRscript.bat", col.names = F, row.names = F, quote = F)
write.csv(mydata, "notRscript_input.csv")
write.csv(mydata, "notRscript_output.csv")
shell.exec("notRscript.bat")
#suppose notRscript.bat does something to script_input.csv and produce script_output.csv
script_result <- list(result = list(read.csv("notRscript_output.csv")), log = list("dummy log text"))
unlink(c("notRscript.bat", "notRscript_input.csv", "notRscript_output.csv"))
###end of function###
script_result_output <- script_result$result[[1]]
script_result_output
So far, I got down to here:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
title = "Basic dashboard"
),
dashboardSidebar(
actionButton("go","Simulate")
),
dashboardBody(
tableOutput("out")
)
)
server <- function(input, output) {
myscript <- reactive("START START")
mydata <- reactive(head(cars))
#code for write.table(myscript()) and write.csv(mydata())
#code for shell.exec()
script_result <- reactive(
list(result = list(read.csv("notRscript_output.csv")), log = list("dummy log text"))
)
#code for unlink()
final <- reactive(script_result()$result[[1]])
final_result <- eventReactive(input$go,{
final()
})
output$out <- renderTable(final_result())
}
shinyApp(ui = ui, server = server)
I could not figure out the part for
- code for write.table() and write.csv()
- code for shell.exec()
- code for unlink()
While there seems to be abundant resources for Shiny application where import/export is the final result and running R script within Shiny, I had less luck on finding resource for Shiny application where import/export is an interim process and it is running non-R script.
Appreciate your expertise.