R/m_home.R

Defines functions m_home_ui m_home_server

# Module UI
  
#' @title   m_home_ui and mod_home_server
#' @description  A shiny Module.
#'
#' @param id shiny id
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @rdname mod_home
#'
#' @keywords internal
#' @export 
#' @importFrom shiny NS tagList 
m_home_ui <- function(id){
  ns <- NS(id)
  shinydashboard::tabItem(
    tabName = "Home", 
    shinydashboard::box(
      width = 12,
      uiOutput(ns("running_bee")),
      actionButton(ns("use_demo_data"), "Use demo data", class="btn-success"),
      br(),
      br(),
      br(),
      textInput(ns('study_directory'), "Project directory"),
      textInput(ns("gh_address"), "Github repository"),
      htmlOutput(ns("project_info")),
      actionButton(ns("create_github_demo"), "Create github repo", class="btn-success", icon=icon("cog")),
      actionButton(ns("reset_app"), "Clear and reset app", class="btn-danger")
    )
    
  )
}
    
# Module Server
    
#' @rdname m_home
#' @export
#' @keywords internal
    
m_home_server <- function(input, output, session, state){
  ns <- session$ns
  
  output$running_bee <- renderUI ({
    "This app is not running on BEE. You may preview some functionality by using the Demo Study"
  })
  
  project_info <- reactiveValues(
    name = NULL,
    path_bee = NULL,
    github_repo = NULL,
    demo = FALSE
  )
  
  info <- reactive ({
    x <- Sys.info()
    list(
      user = x["user"],
      BEE = FALSE
    )
  })
  
  observeEvent(input$use_demo_data, {
    project_info$demo = TRUE
  })

    
  output$project_info <- renderUI({
    req(project_info$demo)

    div(
      h3(tags$strong("User:"), glue::glue("{info()$user}")),
      h3(tags$strong("Study Description:"), "Demo study"),
      p(tags$strong("Path in BEE:"),  "Not Applicable"),
      p(tags$strong("Lopo path:"), glue::glue("{state$lopo_path}")),
      p(tags$strong("Program path:"), glue::glue("{state$pgm_path}")),
      p(tags$strong("Output path:"), glue::glue("{state$output_path}")),
      p(tags$strong("Github repo:"), glue::glue("{state$github_address}")),
      br(),
      p(tags$em("This is a demo study to explore some functionality within the app. Changes made in this session 
        will not persist once the app is closed")),
      br()
      
    )
  })
  
  observe({
    condition <- project_info$demo
    shinyjs::toggle(id="use_demo_data", condition = !condition)
    shinyjs::toggle(id="gh_address", condition = !condition)
    shinyjs::toggle(id="study_directory", condition = !condition)
    
    shinyjs::toggle(id="create_github_demo", condition = condition)
  })
  
  observeEvent(input$reset_app, {
    project_info$demo = FALSE
  })
  
  observeEvent(input$create_github_demo,{
    showModal(modalDialog(
      title = "Creating github repo",
      create_github_ex()
    ))
  
  })
}
    
 
kismet303/lopo3000 documentation built on Dec. 15, 2019, 12:31 a.m.