Bläddra i källkod

Add _reset event that sends back timestamp when text area is cleared

shiny-input
Garrick Aden-Buie 6 år sedan
förälder
incheckning
ccc35d6978
3 ändrade filer med 25 tillägg och 1 borttagningar
  1. +3
    -1
      inst/shiny-input-app/app.R
  2. +21
    -0
      inst/shiny-input-app/dev-shiny-input.Rmd
  3. +1
    -0
      inst/shiny-input-app/typing.js

+ 3
- 1
inst/shiny-input-app/app.R Visa fil

) )


server <- function(input, output, session) { server <- function(input, output, session) {
output$debug <- renderPrint(input$typing)
output$debug <- renderPrint({
str(list(typing = input$typing, typing_reset = input$typing_reset))
})


observeEvent(input$reset, { observeEvent(input$reset, {
resetTypingSpeed("typing") resetTypingSpeed("typing")

+ 21
- 0
inst/shiny-input-app/dev-shiny-input.Rmd Visa fil



This function should take an `inputId` and a `session` object. This function should take an `inputId` and a `session` object.
Use `shiny::getDefaultReactiveDomain()` for the default `session` value. Use `shiny::getDefaultReactiveDomain()` for the default `session` value.

`r github_sha_link("644a8b6c2e8f3719bda89cbd7801a90401c9eadb")`

### Final Step: Extra inputs on the side

In our final app,
we're going to want to know on the Shiny server side
when the user has reset the typing input.
We can watch for the typing speed input to be `NULL`,
but ultimately it's a bit of a hassle
to turn `is.null()`/`!is.null()` into an event.

It will be easier for us if we can simply
send an `{inputId}_reset` event to the server
when the input has changed.

Try adding a `Shiny.setInputValue()`
that sends the current time
to the input ID `{inputId}_reset`
when the `this._timing` property is reset.
Also, update the `debug` output to monitor `input$typing_reset` as well.

+ 1
- 0
inst/shiny-input-app/typing.js Visa fil



if (nchar === 0) { if (nchar === 0) {
this._timing = null this._timing = null
Shiny.setInputValue(el.id + '_reset', Date.now())
return null return null
} }
if (!this._timing && nchar > 0) { if (!this._timing && nchar > 0) {

Laddar…
Avbryt
Spara