Skip to content

Instantly share code, notes, and snippets.

@vpnagraj
Created November 17, 2016 17:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vpnagraj/433876c994e9c2fba8d0d2544a57af67 to your computer and use it in GitHub Desktop.
Save vpnagraj/433876c994e9c2fba8d0d2544a57af67 to your computer and use it in GitHub Desktop.
skeleton of a shiny app to setwd and source R scripts
library(shiny)
options(shiny.reactlog=TRUE)
# define home dir for shiny app
homed <- getwd()
# set up choices to be retrievable in server.R
progchoices <- c("This is a TEST APP" = "testapp/",
"Yet Another Program" = "anotherprog/")
ui <- fluidPage(
titlePanel("CODA Bioinformatics App Launcher"),
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "app",
label = "Select an application to run:",
choices = progchoices),
actionButton("goButton", "Run")
),
mainPanel(
h3(textOutput("message"))
)
)
)
server <- function(input, output) {
runandmessage <- eventReactive(input$goButton, ({
# set working dir
setwd(input$app)
# browser()
# find file to run
filelist <- list.files()
filetorun <- grep(pattern = "RUN", filelist, value = T)
# run it
source(filetorun)
# return to shiny app home dir defined above
setwd(homed)
# construct message
# get the name of the program that was selected to run
progname <- names(progchoices[progchoices==input$app])
# output message
paste0(progname, " successfully ran!")
})
)
output$message <- renderText ({
# execute reactive expression defined above
runandmessage()
})
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment