Преглед изворни кода

Calculate typing speed

shiny-input
Garrick Aden-Buie пре 6 година
родитељ
комит
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

Loading…
Откажи
Сачувај