## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)

## -----------------------------------------------------------------------------
# library(EZRShiny)
# 
# createEZApp("myApp", appName = "My App")
# shiny::runApp("myApp")

## -----------------------------------------------------------------------------
# # App Startup ----
# ## 1.0 Load Libraries ----
# library(shiny)
# library(bslib)
# library(shinyjs)
# library(EZRShiny)
# 
# ## 2.0 Load Basics ----
# options(shiny.maxRequestSize = 300 * 1024^2)   # allow uploads up to 300 MB
# sourceFunctions("Functions")                    # load every .R file in Functions/
# 
# ## 3.0 Universal Vars ----
# appName <- "My App"
# 
# # UI ----
# ui <- UINav(...)
# 
# # Server ----
# server <- function(input, output, session) { ... }
# 
# # Run App ----
# shinyApp(ui = ui, server = server)

## -----------------------------------------------------------------------------
# ui <- UINav(
#   logoFile = "logo.png",   # from the www folder; leave out for no logo
#   appName = "My App",      # leave out to use a global appName variable
#   barColor = "#1F4E79",    # navigation bar color; leave out for the theme default
# 
#   singleTab("Upload", ...),
#   biLevelTab("Results", ...)
# )

## -----------------------------------------------------------------------------
# ui <- UINav(
#   appName = "Tab Tour",
# 
#   # One page
#   singleTab("Upload",
#     navUpload("dataUpload", "Upload a CSV")
#   ),
# 
#   # One page with a sidebar
#   sidebarLevelTab("Table",
#     sidebarElements = list(
#       navSelect("columns", "Columns to show", multiple = TRUE)
#     ),
#     navOutputTable("dataTable")
#   ),
# 
#   # A row of sub tabs
#   biLevelTab("Plots",
#     subSidebarTab("Scatter",
#       sidebarElements = list(navButton("makeScatter", "Make plot")),
#       navOutputPlot("scatterPlot")
#     ),
#     subTab("Side by Side",
#       subTwoColPage(navOutputPlot("leftPlot"), navOutputPlot("rightPlot"))
#     )
#   ),
# 
#   # A menu of tabs, each with its own sub tabs
#   triLevelTab("Models",
#     triSubTab("Linear",
#       subTab("Fit", navOutputText("linearFit")),
#       subTab("Residuals", navOutputPlot("linearResiduals"))
#     ),
#     triSubSidebarTab("Custom",
#       sidebarElements = list(navText("formula", "Model formula")),
#       subTab("Fit", navOutputText("customFit"))
#     )
#   )
# )

## -----------------------------------------------------------------------------
# options(EZRShiny.cardHeight = "70vh")

## -----------------------------------------------------------------------------
# navButton("runData", "Run analysis", tooltipText = "Upload your data first.")

## -----------------------------------------------------------------------------
# navSelect("pcX", "PC for x-axis", choices = paste0("PC", 1:10))
# navSelect("groups", "Groups to compare", choices = groupNames, multiple = TRUE)
# navSelect("tags", "Tags", choices = c("a", "b"), multiple = TRUE, create = TRUE)

## -----------------------------------------------------------------------------
# # UI
# navSelect("groups", "Pick groups", multiple = TRUE)
# 
# # Server
# updateSelectizeInput(session, "groups", choices = unique(theData$Group))

## -----------------------------------------------------------------------------
# navOutputPlotly("pcaPlot", label = "PCA of all samples",
#                 tooltipText = "Each point is one sample, colored by group.")

## -----------------------------------------------------------------------------
# global <- reactiveValues(
#   datasets = list(
#     rawData = NULL
#   )
# )

## -----------------------------------------------------------------------------
# observe({
#   startSection("Run on Start")
# 
#   hideNavTabs(rootID = "Results", tabIDs = c("Table", "Plot"))
#   deactivateItems(c("runAnalysis", "resultsDownload"))
# 
#   endSection("Run on Start")
# })

## -----------------------------------------------------------------------------
# observeEvent(input$runAnalysis, {
#   startSection("Run Analysis")
# 
#   ## Load globals
#   rawData <- global$datasets$rawData
# 
#   ## Inputs
#   alpha <- input$alpha
# 
#   ## Do things
#   results <- runMyAnalysis(rawData, alpha)
# 
#   ## App interactions
#   output$resultsTable <- DT::renderDT({ results })
#   activateItems(c("resultsDownload"))
#   showNavTabs(rootID = "Results", tabIDs = c("Table", "Plot"))
#   nav_select("root", "Results")
# 
#   ## Save globals
#   global$datasets$results <- results
# 
#   endSection("Run Analysis")
# })

## -----------------------------------------------------------------------------
# runExampleApp()

## -----------------------------------------------------------------------------
# exampleFolder <- system.file("examples", "titanicExplorer", package = "EZRShiny")
# list.files(exampleFolder, recursive = TRUE)
# file.copy(exampleFolder, "myCopy", recursive = TRUE)

## -----------------------------------------------------------------------------
# ui <- UINav(
#   logoFile = c("institute_logo.png", "app_logo.png"),
#   logoHeight = c("35vh", "40vh"),
#   appName = appName,
#   barColor = "#005596",
#   ...
# )

