visibilityFuncs {tabler}R Documentation

Show/Hide an element

Description

Show or hide an HTML element in a running tablerApp.

show makes an element visible, hide makes an element invisible, toggle displays the element if it is hidden and hides it if it is visible.

showElement, hideElement, and toggleElement are synonyms for show/hide/ toggle.

If condition is given to toggle, that condition is used to decide whether to show or hide the element: the element is shown when the condition evaluates to TRUE and hidden otherwise.

Usage

show(
  session = getDefaultReactiveDomain(),
  id = NULL,
  anim = FALSE,
  animType = "slide",
  time = 0.5,
  selector = NULL
)

showElement(
  session = getDefaultReactiveDomain(),
  id = NULL,
  anim = FALSE,
  animType = "slide",
  time = 0.5,
  selector = NULL
)

hide(
  session = getDefaultReactiveDomain(),
  id = NULL,
  anim = FALSE,
  animType = "slide",
  time = 0.5,
  selector = NULL
)

hideElement(
  session = getDefaultReactiveDomain(),
  id = NULL,
  anim = FALSE,
  animType = "slide",
  time = 0.5,
  selector = NULL
)

toggle(
  session = getDefaultReactiveDomain(),
  id = NULL,
  anim = FALSE,
  animType = "slide",
  time = 0.5,
  selector = NULL,
  condition = NULL
)

toggleElement(
  session = getDefaultReactiveDomain(),
  id = NULL,
  anim = FALSE,
  animType = "slide",
  time = 0.5,
  selector = NULL,
  condition = NULL
)

Arguments

session The session object passed by tablerApp to the server function.
id The id of the element/HTML tag.
anim If TRUE then animate the behaviour.
animType The type of animation to use, either "slide" or "fade".
time The number of seconds to make the animation last.
selector CSS selector of the elements to show/hide. Ignored if the id argument is given. For example, to select all span elements with class x, use selector = "span.x".
condition An optional argument to toggle, see 'Details' below.

Details

This is a dependency-free adaptation of shinyjs's show/hide/toggle functions for tabler, which does not use or depend on shiny. Instead of relying on a Shiny session, these functions use the plain-list session object created by tablerApp and passed as the third argument to the server function.

See Also

tablerApp

Examples

if (interactive()) {
  ui <- page(
    title = "Show/Hide Example",
    body = body(
      actionButton("btn", "Click me"),
      div(id = "panel", "Watch what happens to me")
    )
  )

  server <- function(input, output, session) {
    observeEvent(input$btn, {
      # Change the following line for more examples
      toggle(session, "panel")
    })
  }

  tablerApp(ui, server)
}
## Not run:
# The function call in the above app can be replaced by any of the
# following examples to produce similar apps
toggle(session, id = "panel")
toggle(session, "panel", TRUE)
toggle(session, "panel", TRUE, "fade", 2)
toggle(session, id = "panel", time = 1, anim = TRUE, animType = "slide")
show(session, "panel")
show(session, id = "panel", anim = TRUE)
hide(session, "panel")
hide(session, id = "panel", anim = TRUE)

## End(Not run)

## toggle can be given an optional `condition` argument, which
## determines if to show or hide the element
if (interactive()) {
  ui <- page(
    title = "Conditional Toggle",
    body = body(
      checkboxInput("checkbox", "Show the text", TRUE),
      div(id = "element", "Watch what happens to me")
    )
  )

  server <- function(input, output, session) {
    observe({
      toggle(session, id = "element", condition = input$checkbox)
    })
  }

  tablerApp(ui, server)
}

Loading...