Data Capture System in Javascript, integrated into R Shiny
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.
In the UI part of your dashboard:
useShinyjs(),
includeScript(path = "script.js"),
-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.
tags$script("document.addEventListener('click',function(event){mouselog(event)});"),
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:
onclick("btn_download", runjs("stock_event+= logging_ended+','; Meta();Btn(stock_event,link_event,head_fields1);Btn(stock_frequence,link_continuous_measurment,head_fields2);Btn(stock_meta,link_meta,head_fields3)"))
onclick("btn_clear", runjs("stock_event='';stock_continuous_measurement='';stock_frequence='';stock_meta=''"))
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.
<script src="https://github.com/med-material/r-shiny-js-data-capture/raw/main/script.js"></script>
<body id="example" onmouseover="mouselog(event)" onmouseout="mouselog(event)" onclick="mouselog(event)" onpointermove="ContinuousMeasurement(event)">
-Do the same for continuous measurements by calling the "pointermove" event with the "continuous measurement" function. Like this :
onpointermove="ContinuousMeasurement(event)"
-Then you just have to create the 2 buttons as for the dashboard:
<input type="button" onclick="stock_event='';stock_continuous_measurement='';stock_frequence='';stock_meta=''" value="Clear">
<input type="button" id="btn" onclick="stock_event+= logging_ended+','; Meta();Btn(stock_event,link_event,head_fields1);Btn(stock_frequence,link_continuous_measurment,head_fields2);Btn(stock_meta,link_meta,head_fields3)" value="download csv">
For meta data, they are captured when pressing the download button with the meta() function call.
At this time, we are capturing these events :