Skip to contents

A button that appears once the page has been scrolled down, and returns it to the top when clicked.

Usage

el_backtop(
  id = NULL,
  content = NULL,
  target = NULL,
  visibility_height = NULL,
  right = NULL,
  bottom = NULL,
  width = NULL,
  slots = NULL,
  events = NULL,
  on = NULL,
  session = NULL
)

update_el_backtop(
  session = shiny::getDefaultReactiveDomain(),
  id,
  visibility_height = NULL,
  right = NULL,
  bottom = NULL,
  target = NULL
)

Arguments

id

Button ID. Auto-generated if NULL.

content

Contents of the button. NULL for Element's own arrow icon.

target

CSS selector of the element that scrolls. NULL for the page.

visibility_height

Scroll distance in pixels before the button appears. Default 200.

right

Distance from the right edge, in pixels. Default 40.

bottom

Distance from the bottom edge, in pixels. Default 40.

width

Component width, as a CSS unit.

slots

Named list of Element slot contents, such as list(title = shiny::tags$b("Bold")). A shiny.element component given here is absorbed rather than nested. For a scoped slot, write the template with template().

events

Element's events to report besides those reported unasked, by name: events = "node_drop" reports input$<id>_node_drop. The component's are listed under "Shiny inputs", and by el_events(); a name it does not have is an error.

on

Handlers of your own, for an event not reported or to send something else: a named list of JS() functions, one per event – Element's, or a DOM event with Vue's modifiers ("keyup.enter"). Each is called with report and the event's arguments; report(name, value) sets input$<id>_<name>. See el_widget().

session

In el_backtop(), deprecated: inside a module, wrap id in ns(), as for any Shiny input; a session given here namespaces id once more, with a warning. In update_el_backtop(), the Shiny session, the current one by default, as for shiny::updateTextInput().

Value

A Shiny UI element.

Shiny inputs

InputReportedValue
input$<id>_clickunaskedtriggers when click.

The same list as el_events("el_backtop"), which says how an event's arguments travel.

Binding

Every argument can follow v_bind() or v_model() except content (content drawn by R); width (the mount point's style).

Updating from the server

Server-side update for el_backtop().

Every other argument of el_backtop() that can change once it is drawn is an argument here too, under the same name. One left NULL stays as it is; NA returns it to Element's default.

update_el_backtop() is called for its side effect and returns NULL invisibly.

Examples

el_backtop("top")
#> <div id="top" data-shiny-vue style="display: contents">
#>   <script type="text/x-template" data-shiny-vue-template><div id="top_container" style="display: contents">
#>   <el-backtop v-bind="$optional(&#39;backtop&#39;)" @click="svEmitClick"></el-backtop>
#> </div></script>
#>   <script type="application/json" data-shiny-vue-options>{"options":{"data":{"target":null,"visibilityHeight":null,"right":null,"bottom":null},"methods":{"svEmitClick":"function() { window.shinyVue.emit('top', 'click', arguments); }"}},"input":null,"rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"backtop":{"target":"target","visibility-height":"visibilityHeight","right":"right","bottom":"bottom"}},"evals":["options.methods.svEmitClick"]}</script>
#> </div>
el_backtop("top", visibility_height = 100, right = 20, bottom = 20)
#> <div id="top" data-shiny-vue style="display: contents">
#>   <script type="text/x-template" data-shiny-vue-template><div id="top_container" style="display: contents">
#>   <el-backtop v-bind="$optional(&#39;backtop&#39;)" @click="svEmitClick"></el-backtop>
#> </div></script>
#>   <script type="application/json" data-shiny-vue-options>{"options":{"data":{"target":null,"visibilityHeight":100,"right":20,"bottom":20},"methods":{"svEmitClick":"function() { window.shinyVue.emit('top', 'click', arguments); }"}},"input":null,"rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"backtop":{"target":"target","visibility-height":"visibilityHeight","right":"right","bottom":"bottom"}},"evals":["options.methods.svEmitClick"]}</script>
#> </div>

# Scrolling a panel rather than the page
el_backtop("panel_top", target = "#report")
#> <div id="panel_top" data-shiny-vue style="display: contents">
#>   <script type="text/x-template" data-shiny-vue-template><div id="panel_top_container" style="display: contents">
#>   <el-backtop v-bind="$optional(&#39;backtop&#39;)" @click="svEmitClick"></el-backtop>
#> </div></script>
#>   <script type="application/json" data-shiny-vue-options>{"options":{"data":{"target":"#report","visibilityHeight":null,"right":null,"bottom":null},"methods":{"svEmitClick":"function() { window.shinyVue.emit('panel_top', 'click', arguments); }"}},"input":null,"rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"backtop":{"target":"target","visibility-height":"visibilityHeight","right":"right","bottom":"bottom"}},"evals":["options.methods.svEmitClick"]}</script>
#> </div>
if (interactive()) {
  # inside a server function
  observeEvent(input$compact, {
    update_el_backtop(session, "top", right = 10, bottom = 10)
  })
}