Created
November 17, 2016 17:43
-
-
Save vpnagraj/433876c994e9c2fba8d0d2544a57af67 to your computer and use it in GitHub Desktop.
skeleton of a shiny app to setwd and source R scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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