Просмотр исходного кода

Calculate typing speed

shiny-input
Garrick Aden-Buie 6 лет назад
Родитель
Сommit
fa02cb2314
3 измененных файлов: 33 добавлений и 1 удалений
  1. +2
    -0
      inst/shiny-input-app/app.R
  2. +23
    -0
      inst/shiny-input-app/dev-shiny-input.Rmd
  3. +8
    -1
      inst/shiny-input-app/typing.js

+ 2
- 0
inst/shiny-input-app/app.R Просмотреть файл

library(shiny) library(shiny)


options(scipen = 1e3)

typingSpeedInput <- function(inputId, label, placeholder = NULL) { typingSpeedInput <- function(inputId, label, placeholder = NULL) {
.label <- label .label <- label
htmltools::withTags( htmltools::withTags(

+ 23
- 0
inst/shiny-input-app/dev-shiny-input.Rmd Просмотреть файл



Include the timing value in the data returned to Shiny Include the timing value in the data returned to Shiny
so that you can verify it's working. so that you can verify it's working.

(`r github_sha_link("073186bcc9741cb2494b4b9a17042ea5716a7dd5")`)

### Your Turn: How Fast?

Now you're ready to calculate typing statistics.

Here's the idea:
each time the user presses a key,
we calculate the `elapsed` time in seconds since they started typing.

Then, from that value calculate:

- words per minute (`wpm`)
- characters per second (`cps`)

Return an object/list with

- `wpm`,
- `cps`,
- the current timestamp as `time` and
- the `text` in the input


+ 8
- 1
inst/shiny-input-app/typing.js Просмотреть файл

return null return null
} }


return {nchar, nword, timing: this._timing};
let time = Date.now()
let elapsed = (time - this._timing) / 1000
return {
wpm: nword / elapsed * 60,
cps: nchar / elapsed,
time,
text: el.value
}
}, },
setValue: function(el, value) { setValue: function(el, value) {
// This method is used for restoring the bookmarked state of your input // This method is used for restoring the bookmarked state of your input

Загрузка…
Отмена
Сохранить