Pārlūkot izejas kodu

Add a reset button to trigger the recieveMessage() method

shiny-input
Garrick Aden-Buie pirms 6 gadiem
vecāks
revīzija
269e4ebdc4
3 mainītis faili ar 22 papildinājumiem un 2 dzēšanām
  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 Parādīt failu

ui <- fluidPage( ui <- fluidPage(
# textAreaInput("typing", "Type here..."), # textAreaInput("typing", "Type here..."),
typingSpeedInput("typing", "Type here..."), typingSpeedInput("typing", "Type here..."),
actionButton("reset", "Reset"),
verbatimTextOutput("debug") verbatimTextOutput("debug")
) )


server <- function(input, output, session) { server <- function(input, output, session) {
output$debug <- renderPrint(input$typing) output$debug <- renderPrint(input$typing)

observeEvent(input$reset, {
session$sendInputMessage("typing", TRUE)
})
} }


shinyApp(ui, server) shinyApp(ui, server)

+ 13
- 0
inst/shiny-input-app/dev-shiny-input.Rmd Parādīt failu



Find a good delay rate. 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 Parādīt failu

// and its elements to reflect the given data. // and its elements to reflect the given data.
// The messages are sent from R/Shiny via // The messages are sent from R/Shiny via
// R> session$sendInputMessage(inputId, data) // 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 // 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) { subscribe: function(el, callback) {
// Listen to events on your input element. The following block listens to // Listen to events on your input element. The following block listens to

Notiek ielāde…
Atcelt
Saglabāt