简体   繁体   中英

How to pass the R script into R shiny

I already have a simple defined function process in the R script. I want to design an R shiny app to enter the input keywords. After entering the searching keywords and R shiny will automatically jump to my function I wrote in the R script to get the output and reflect back on the R shiny page.

I am curious on how to connect the R shiny and R script. Also, how to put the input that I entered in R shiny automatic on the function I made.

I am the beginner of R and thanks for helping me.

Normally too broad, but I can help you quickly.

source("path/to/my/script.R")


library(shiny)

ui <- fluidPage(

    titlePanel("Run script from Button click"),
    actionButton("script", "Run the Script")
    )


server <- function(input, output) {

    observeEvent(input$script, {
        source("script.R")
    })

}

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

Load the script with source and use observeEvent to run it.

you can put your functions in the main folder of your R shiny app and then use

  source('./functions.R')

in the source to load them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM