You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1006B

  1. library(shiny)
  2. options(scipen = 1e3)
  3. typingSpeedInput <- function(inputId, label, placeholder = NULL) {
  4. .label <- label
  5. htmltools::withTags(
  6. div(
  7. class = "form-group typing-speed",
  8. label(class = "control-label", `for` = inputId, .label),
  9. textarea(id = inputId, class = "form-control", placeholder = placeholder),
  10. htmltools::htmlDependency(
  11. name = "typingSpeed",
  12. version = "0.0.1",
  13. src = ".",
  14. script = "typing.js",
  15. all_files = FALSE
  16. )
  17. )
  18. )
  19. }
  20. resetTypingSpeed <- function(inputId, session = getDefaultReactiveDomain()) {
  21. session$sendInputMessage("typing", TRUE)
  22. }
  23. ui <- fluidPage(
  24. # textAreaInput("typing", "Type here..."),
  25. typingSpeedInput("typing", "Type here..."),
  26. actionButton("reset", "Reset"),
  27. verbatimTextOutput("debug")
  28. )
  29. server <- function(input, output, session) {
  30. output$debug <- renderPrint(input$typing)
  31. observeEvent(input$reset, {
  32. resetTypingSpeed("typing")
  33. })
  34. }
  35. shinyApp(ui, server)