No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

71 líneas
1.7KB

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