-
-
Save vfulco/1fbd88b5abc8bfffa7d5f6483341bbba 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