Quellcode durchsuchen

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

shiny-input
Garrick Aden-Buie vor 6 Jahren
Ursprung
Commit
ccc35d6978
3 geänderte Dateien mit 25 neuen und 1 gelöschten Zeilen
  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 Datei anzeigen

@@ -32,7 +32,9 @@ ui <- fluidPage(
)

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, {
resetTypingSpeed("typing")

+ 21
- 0
inst/shiny-input-app/dev-shiny-input.Rmd Datei anzeigen

@@ -479,3 +479,24 @@ refactor it into a `resetTypingSpeed()` function.

This function should take an `inputId` and a `session` object.
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 Datei anzeigen

@@ -22,6 +22,7 @@ $.extend(typingSpeed, {

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

Laden…
Abbrechen
Speichern