click_event: associate a event with an input value

Description Usage Arguments See Also Examples

View source: R/event.R

Description

associate a click on an HTML element with an input value. The name of input value is free.

Usage

1
click_event(id, event_id = paste0(id, "_event"), event_type = "click")

Arguments

id

shiny input id on which click listener has been set

event_id

reactive input to be incremented when click if fired.

event_type

the type of event, can be one of: "click", "dblclick", "hover", "mousedown", "mouseenter", "mouseleave", "mousemove", "mouseout", "mouseover", "mouseup".

See Also

Other javascript functions: ability, activate, html_class, html_toogle

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(shinytools)
library(shiny)

if (interactive()) {
  options(device.ask.default = FALSE)

  ui <- fluidPage(
    titlePanel("Hello dghiesse!"),
    load_jstools(),
    sidebarLayout(
      sidebarPanel(
        div(span(id = "aspan", "click me")),
        click_event("aspan", "myclick")
      ),
      mainPanel(
        htmlOutput(outputId = "content")
      )
    )
  )

  server <- function(input, output) {
    observeEvent(input$myclick, {
      output$content <- renderUI({
        div(paste0("aspan has been clicked ",
                   input$myclick, " times"))
      })
    })
  }

  print(shinyApp(ui, server))
}

ardata-fr/shinytools documentation built on Nov. 15, 2019, 7:53 p.m.