Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

78 Zeilen
1.9KB

  1. library(shiny)
  2. library(frappeCharts)
  3. options(scipen = 1e3)
  4. typingSpeedInput <- function(inputId, label, placeholder = NULL) {
  5. .label <- label
  6. htmltools::withTags(
  7. div(
  8. class = "form-group typing-speed",
  9. label(class = "control-label", `for` = inputId, .label),
  10. textarea(id = inputId, class = "form-control", placeholder = placeholder),
  11. htmltools::htmlDependency(
  12. name = "typingSpeed",
  13. version = "0.0.1",
  14. src = ".",
  15. script = "typing.js",
  16. all_files = FALSE
  17. )
  18. )
  19. )
  20. }
  21. resetTypingSpeed <- function(inputId, session = getDefaultReactiveDomain()) {
  22. session$sendInputMessage("typing", TRUE)
  23. }
  24. ui <- fluidPage(
  25. # textAreaInput("typing", "Type here..."),
  26. typingSpeedInput("typing", "Type here..."),
  27. actionButton("reset", "Reset"),
  28. frappeCharts::frappeChartOutput("chart_typing_speed")
  29. # verbatimTextOutput("debug")
  30. )
  31. server <- function(input, output, session) {
  32. output$debug <- renderPrint({
  33. str(list(typing = input$typing, typing_reset = input$typing_reset))
  34. })
  35. observeEvent(input$reset, {
  36. resetTypingSpeed("typing")
  37. })
  38. wpm <- reactiveValues(time = c(), wpm = c())
  39. observeEvent(input$typing_reset, {
  40. wpm$time <- c()
  41. wpm$wpm <- c()
  42. })
  43. observeEvent(input$typing, {
  44. req(input$typing)
  45. wpm$time <- c(wpm$time, input$typing$time)
  46. wpm$wpm <- c(wpm$wpm, input$typing$wpm)
  47. })
  48. output$chart_typing_speed <- frappeCharts::renderFrappeChart({
  49. frappeCharts::frappeChart(
  50. data.frame(time = 0, wpm = 0),
  51. type = "line",
  52. title = "Your Typing Speed",
  53. is_navigable = FALSE,
  54. axisOptions = list(xIsSeries = TRUE),
  55. lineOptions = list(regionFill = TRUE)
  56. )
  57. })
  58. observeEvent(wpm$time, {
  59. frappeCharts::updateFrappeChart(
  60. inputId = "chart_typing_speed",
  61. data = data.frame(time = wpm$time, wpm = wpm$wpm)
  62. )
  63. })
  64. }
  65. shinyApp(ui, server)