1

I have developed an R Script and now I want to connect this R Script with Shiny app. i.e., I am developing my GUI in Shiny but I am facing the problems in connecting the RScript and Shiny. I want to call the output of the RScript using the Shiny app.

I have looked around the RStudio Shiny app development tutorials but it didn't help me in connectivity. Is there any way I solve this problem?

If possible can you give me the code for "How can I call RScript on button click using shiny app".

UPDATE:

Can you help me with something like this: I want to upload the csv file using shiny app (GUI) and then based on CSV file, I have made a RScript which uses plot() function, and this plot is what I want to show over the Shiny app GUI.

  • http://shiny.rstudio.com/tutorial/lesson5/ Here is an extensive explanation. – Verena Haunschmid Jul 13 '15 at 06:10
  • @VerenaHaunschmid yes, I did saw that lesson from the RStudios. But I am keep on getting errors..! I can't find a way out. –  Jul 14 '15 at 05:41
  • You need to provide source code and error messages, otherwise no on can know what goes wrong. – Verena Haunschmid Jul 14 '15 at 05:42
  • @VerenaHaunschmid `isolate({source("C:\Stu\R\ABC.R")})` Can you tell me how can i format this to upload any file from my computer? Error : '\m' is an unrecognized escape in character string starting ""C:\S" –  Jul 14 '15 at 05:54
  • Why are you using isolate? Why do you want to call RScript on button click? Why don't you do it like in the answer by @daattali? I am sorry but your question is still not clear, please provide more info on 1) what you want to do, 2) what you have tried and 3) why the suggested solution doesn't work for you. To upload a csv file you need fileInput() – Verena Haunschmid Jul 14 '15 at 06:03

1 Answers1

5

You can just use source like you would a normal R script. Let's say you have an R script called myscript.R and it has a function called calculate() and you want to call it when the user presses a button in Shiny.

source("myscript.R")

runApp(shinyApp(
  ui = fluidPage(
    actionButton("btn", "calculate")
  ),
  server = function(input, output, session) {
    observeEvent(input$btn, {
      calculate()
    })
  }
))
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • I am using the source() function. But it seems that I can't call the files at run time. I am getting the error on that. Can you help me with something like this: I want to upload the csv file using shiny app (GUI) and then based on CSV file, I have made a RScript which uses plot(), and this plot is what I want to show over the Shiny GUI –  Jul 14 '15 at 05:45