Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. library(shiny)
  2. ui <- fluidPage(
  3. actionButton(inputId = "dummy_button", label = "This is a button"),
  4. verbatimTextOutput(outputId = "detector"),
  5. tags$script('
  6. var counter = 0;
  7. var ctrlDown = false,
  8. ctrlKey = 17,
  9. cKey = 67;
  10. $(document).keydown(function(e) {
  11. if (e.keyCode == ctrlKey ) ctrlDown = true;
  12. }).keyup(function(e) {
  13. if (e.keyCode == ctrlKey ) {
  14. ctrlDown = false;
  15. counter = counter + 1
  16. Shiny.onInputChange("mydata",counter );
  17. }
  18.  
  19. });
  20. ')
  21. )
  22.  
  23.  
  24.  
  25. server <- function(input, output,session) {
  26.  
  27. counter <- reactiveVal(0)
  28.  
  29. observeEvent(input$mydata,{
  30. counter(counter() + 1)
  31.  
  32. })
  33.  
  34. output$detector <- renderPrint({
  35. req(input$mydata)
  36. paste("button clicked", counter(), "times")
  37. })
  38.  
  39. }
  40.  
  41. # Run the application
  42. shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement