Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- ui <- fluidPage(
- actionButton(inputId = "dummy_button", label = "This is a button"),
- verbatimTextOutput(outputId = "detector"),
- tags$script('
- var counter = 0;
- var ctrlDown = false,
- ctrlKey = 17,
- cKey = 67;
- $(document).keydown(function(e) {
- if (e.keyCode == ctrlKey ) ctrlDown = true;
- }).keyup(function(e) {
- if (e.keyCode == ctrlKey ) {
- ctrlDown = false;
- counter = counter + 1
- Shiny.onInputChange("mydata",counter );
- }
- });
- ')
- )
- server <- function(input, output,session) {
- counter <- reactiveVal(0)
- observeEvent(input$mydata,{
- counter(counter() + 1)
- })
- output$detector <- renderPrint({
- req(input$mydata)
- paste("button clicked", counter(), "times")
- })
- }
- # Run the application
- shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement