Bläddra i källkod

Add a reset button to trigger the recieveMessage() method

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

+ 5
- 0
inst/shiny-input-app/app.R Visa fil

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

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

@@ -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.

+ 4
- 2
inst/shiny-input-app/typing.js Visa fil

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

Laddar…
Avbryt
Spara