R/slider.R

Defines functions slider_server slider_ui

Documented in slider_server slider_ui

#' Slider module UI
#'
#' @description A slider module UI that can accept dynamic inputs on the server-side
#' declaration
#' @param id is unique ID associated with the slider for the UI namespace
#'
#' @return HTML UI code for a shiny application
#'
#' @importFrom shiny uiOutput
#' @export
slider_ui <- function(id) {
  ns <- NS(id)
  uiOutput(ns("slider"))
}

#' Slider module Server
#'
#' @description A slider module UI that can accept dynamic inputs on the server-side
#' declaration
#' @param input list of inputs used in the shiny application session
#' @param output list of outputs used the shiny application session
#' @param session The shiny app session object
#' @param label The label of the \code{sliderInput} function. Converted to reactive later for enabling encapsulation
#' @param min The minimum of numbers that can be used by the \code{sliderInput} function.
#' @param max The maximum of numbers that can be used by the \code{sliderInput} function.
#' @param value The default value of the slider UI
#' @param dragRange Logical value to determine whether or not the slider can drag the range
#'
#' @return Numeric value or scalar
#' @importFrom shiny sliderInput
#' @importFrom shiny reactive
#' @export


slider_server <- function(input, output, session,
                          label = "Select Transaction Weeks",
                          min = 1,
                          max = 52,
                          value = c(1,8),
                          dragRange = T)
{
ns<-session$ns
  output[['slider']]<-renderUI(sliderInput(
    ns("slider"),
    label = label,
    min = min,
    max = max,
    value = value,
    dragRange = dragRange
  ))

  return(list(selected = reactive(input$slider)))
}
HarryRosen/hrimodules documentation built on Jan. 11, 2022, 12:36 a.m.