Skip to content

Instantly share code, notes, and snippets.

@vfulco
Forked from vpnagraj/app.R
Created March 29, 2018 14:41
Show Gist options
  • Select an option

  • Save vfulco/1fbd88b5abc8bfffa7d5f6483341bbba to your computer and use it in GitHub Desktop.

Select an option

Save vfulco/1fbd88b5abc8bfffa7d5f6483341bbba to your computer and use it in GitHub Desktop.

Revisions

  1. @vpnagraj vpnagraj created this gist Nov 17, 2016.
    59 changes: 59 additions & 0 deletions app.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    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)