| visibilityFuncs {tabler} | R Documentation |
Show/Hide an element
Description
Show or hide an HTML element in a running tabler_app.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.show_element, hide_element, and
toggle_element 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 = get_default_reactive_domain(),
id = NULL,
anim = FALSE,
anim_type = "slide",
time = 0.5,
selector = NULL
)
hide(
session = get_default_reactive_domain(),
id = NULL,
anim = FALSE,
anim_type = "slide",
time = 0.5,
selector = NULL
)
toggle(
session = get_default_reactive_domain(),
id = NULL,
anim = FALSE,
anim_type = "slide",
time = 0.5,
selector = NULL,
condition = NULL
)
Arguments
session |
The session object passed by tabler_app
to the server function.
|
id |
The id of the element/HTML tag. |
anim |
If TRUE then animate the behaviour.
|
anim_type |
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
tabler_app and passed as the third argument to the
server function.
See Also
tabler_app
Examples
if (interactive()) {
ui <- page(
title = "Show/Hide Example",
body = body(
action_button("btn", "Click me"),
div(id = "panel", "Watch what happens to me")
)
)
server <- function(input, output, session) {
observe_event(input$btn, {
# Change the following line for more examples
toggle(session, "panel")
})
}
tabler_app(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, anim_type = "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(
checkbox_input("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)
})
}
tabler_app(ui, server)
}