소스 검색

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

shiny-input
Garrick Aden-Buie 6 년 전
부모
커밋
ccc35d6978
3개의 변경된 파일과 25개의 추가작업 그리고 1개의 파일을 삭제
  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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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) {

Loading…
취소
저장