med-material / r-shiny-js-data-capture

Data Capture System in Javascript, integrated into R Shiny
MIT License
1 stars 1 forks source link

r-shiny-js-data-capture

Data Capture System in Javascript, integrated into R Shiny

Working principle

This data capture module allows us to capture the events of our choice on any type of dashboard or website. So with this module we capture 3 types of data:

These 3 types of data correspond to the 3 csv files that we will recover after each session.

How to use it

If you use an R dashboard

In the UI part of your dashboard:

-Then to capture continuous measurements, include these 2 lines:

tags$script("document.addEventListener('pointermove',function(event){ContinuousMeasurement(event)});"),
    tags$script("setInterval(frequence,16)"),

The "continuousMeasurement" function is already in the "script.js" file, it allows the capture of continuous measurements. The "Frequence" function is already in the "script.js" file, it allows the capture of continuous measurements every 16ms.

The "mouselog" function is already in the "script.js" file, it allows the capture of events.

Here is an example covering all the previous points :

shinyUI(fluidPage(
    includeCSS("custom.css"),
    useShinyjs(),
    includeScript(path = "script.js"),
    tags$script("document.addEventListener('pointermove',function(event){ContinuousMeasurement(event)});"),
    tags$script("setInterval(frequence,16)"),
    tags$script("document.addEventListener('pointerdown',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('pointerup',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('pointerover',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('pointerout',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('click',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('keypress',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('scroll',function(event){mouselog(event)});"),
    tags$script("document.addEventListener('gesturechange',function(event){mouselog(event)});"),

The last thing to do in the UI part is to create two buttons like this :

actionButton("btn_download", "Download CSV"),
    actionButton("btn_clear", "Clear"),

In the Server part of your dashboard:

It just corresponds to the different actions when clicking the buttons. For meta data, they are captured when pressing the download button with the meta() function call.

If you use a website

For meta data, they are captured when pressing the download button with the meta() function call.

Composition of CSV files

The events file

At this time, we are capturing these events :

Composition

The continuous measurement file

The meta file