| @@ -23,11 +23,16 @@ typingSpeedInput <- function(inputId, label, placeholder = NULL) { | |||
| ui <- fluidPage( | |||
| # textAreaInput("typing", "Type here..."), | |||
| typingSpeedInput("typing", "Type here..."), | |||
| actionButton("reset", "Reset"), | |||
| verbatimTextOutput("debug") | |||
| ) | |||
| server <- function(input, output, session) { | |||
| output$debug <- renderPrint(input$typing) | |||
| observeEvent(input$reset, { | |||
| session$sendInputMessage("typing", TRUE) | |||
| }) | |||
| } | |||
| shinyApp(ui, server) | |||
| @@ -454,3 +454,16 @@ Try various settings of | |||
| Find a good delay rate. | |||
| ### Almost done: Implement `receiveMessage()` | |||
| There's not much we'd want to do from the server side | |||
| in terms of updating the typing area. | |||
| But maybe we'd like to be able to add a "Reset" button. | |||
| Write a method that, | |||
| when it recieves a `true` value from the server, | |||
| clears the text input area. | |||
| Add a reset button to your app that uses `shiny$sendInputMessage()` | |||
| to send `typing` a `TRUE` | |||
| whenever the button is clicked. | |||
| @@ -53,10 +53,12 @@ $.extend(typingSpeed, { | |||
| // and its elements to reflect the given data. | |||
| // The messages are sent from R/Shiny via | |||
| // R> session$sendInputMessage(inputId, data) | |||
| console.error('typingSpeed.receiveMessage() is not yet defined'); | |||
| // If you want the update to trigger reactivity, trigger a subscribed event | |||
| // $(el).trigger("keyup") | |||
| if (typeof data === 'boolean' && data) { | |||
| el.value = '' | |||
| $(el).trigger('keyup') | |||
| } | |||
| }, | |||
| subscribe: function(el, callback) { | |||
| // Listen to events on your input element. The following block listens to | |||