R/app.R

Defines functions run_shiny server ui

Documented in run_shiny server ui

#' Title
#'
#' @include module_lab_submission.R module_design_run.R
#'
#' @export
ui <- function() {
    shinymanager::secure_app(shiny::shinyUI(
        shiny::fluidPage(
            shinyjs::useShinyjs(),
            theme = shinythemes::shinytheme("cosmo"),
            shiny::navbarPage(
                title = "covidApp",
                id = "tabs",

                # TAB1: Insert metadata
                shiny::tabPanel(
                    title = "Load metadata",
                    value = "tab_1",
                    lab_submission_module_ui("tab1")
                ),

                # TAB2: Download samples for library generation
                shiny::tabPanel(
                    title = "Design run",
                    value = "tab_2",
                    design_run_module_ui("tab2")
                )
            )
        )
    ))
}

#' Title
#'
#' @export
server <- function(){
    function(input, output, session) {
        res_auth <- shinymanager::secure_server(
            check_credentials <- shinymanager::check_credentials(credentials)
        )

        ## Module tab 1
        lab_submission_module_server("tab1")

        ## Module tab 2
        design_run_module_server("tab2")

        ## Conditional tab by user type
        shiny::observe({
            if (is.null(res_auth$module)) {
                shiny::hideTab(inputId = "tabs", target = "tab_1")
            } else {
                if (res_auth$module == 1) {
                    shiny::showTab(inputId = "tabs", target = "tab_1")
                    shiny::hideTab(inputId = "tabs", target = "tab_2")
                } else {
                    shiny::hideTab(inputId = "tabs", target = "tab_1")
                    shiny::showTab(inputId = "tabs", target = "tab_2")
                }
            }
        })
    }
}

#' Title
#'
#' @export
run_shiny <- function() {
    shiny::runApp(list(ui = ui(), server = server()))
}
MicrobialGenomics/covidseq documentation built on Jan. 27, 2021, 7:58 p.m.