R/shiMo_startPage.R

Defines functions shiMo_startPageInput shiMo_startPage

Documented in shiMo_startPage shiMo_startPageInput

#' xxx
#'
#' @param id x
#'
#' @return xxx
#' @export
#'
#' @examples
shiMo_startPageInput <- function(id){

  ns <- shiny::NS(id)

  shiny::uiOutput(ns("startPage"))

}



#' Title
#'
#' @param input x
#' @param output x
#' @param upAppSettings x
#' @param session x
#'
#' @return
#' @export
#'
#' @examples
shiMo_startPage <- function(input, output, session){

  # Reactive variables
  # -------------------------------------------------------------------- #

  drop_download("packTest/resultsList.rds", local_path = "resultsList.rds", overwrite = TRUE)

  r <- shiny::reactiveValues(
    result = "?",
    resultId = 0,
    resultsList = readRDS("resultsList.rds")
  )

  # resultsList <- c(
  #   "Salut ca va?",
  #   "Lave toi les mains!",
  #   "Tu dis pas bonjour?",
  #   "C'est toi le pangolin!",
  #   "Reste chez oit!",
  #   "Tu sais que t'es pas beau.elle?"
  # )
  # saveRDS(resultsList, file = "resultsList.rds")
  # drop_upload("resultsList.rds", path = "packTest")

  # Displays
  # -------------------------------------------------------------------- #

  output$startPage <- shiny::renderUI({

    ns <- session$ns

    shiny::fluidPage(

      shiny::h1("FUN TIME"),
      shiny::br(),
      shiny::h2(shiny::uiOutput(ns("resultDisplay"))),
      shiny::br(),
      shiny::actionButton(ns("butbutbutton"), shiny::h4("Clique moi")),
      shiny::br(),
      shiny::br(),
      shiny::textInput(ns("newSentence"), label = "Ajouter une phrase:"),
      shiny::actionButton(ns("okNew"), label = "OK")

    )

  })

  output$resultDisplay <- shiny::renderText({

    ns <- session$ns

    as.character(r$result)

  })


  # Events
  # -------------------------------------------------------------------- #

  shiny::observeEvent(input$butbutbutton, {

    if(input$butbutbutton == 1){

      shiny::updateActionButton(session, "butbutbutton", label = HTML(paste0(tags$h4("Encore!"))))

    }

    newId <- r$resultId

    while(newId == r$resultId | newId == 0){

      newId <- ceiling(runif(1, 0, length(r$resultsList)))

    }

    r$resultId <- newId

    r$result <- r$resultsList[r$resultId]

  }, ignoreNULL = T, ignoreInit = T)


  shiny::observeEvent(input$okNew, {

    req(input$newSentence)

    resultsList <- c(r$resultsList, input$newSentence)

    saveRDS(resultsList, file = "resultsList.rds")
    drop_upload("resultsList.rds", path = "packTest")

    drop_download("packTest/resultsList.rds", local_path = "resultsList.rds", overwrite = TRUE)

    r$resultsList <- readRDS("resultsList.rds")

    shiny::updateTextInput(session, "newSentence", value = "")

  }, ignoreNULL = T, ignoreInit = T)

}
BenoitO/packTest documentation built on April 3, 2020, 4:11 a.m.