Make trial data available on external-html #2512
madebyafox
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hi @madebyafox, this is probably a question for @jodeleeuw, but I just wanted to say that you're more than welcome to submit a PR for changes to the external-html plugin and we'll review it ASAP. Thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I study data visualization, and have been using jspsych to run studies where users see a complex visualization and answer a question. To accomplish this, I've been using the external-html plugin, and then writing my own (usually rather complex) d3 scripts that controls the rendering of an svg into the DOM for the (interactive) visualization. (I've thought about writing a plugin for this, but the visualizations themselves are generated in D3 and so study specific, it just didn't seem worthwhile).
One limitation of the current version of the external-html plugin, however, is that scripts executed on whatever external html is being displayed cannot access any jsPsych variables, including trial level data.
Thus far I've worked around this limitation by using localstorage
For example... to tell the stimulus.html page to generate a scatterplot graph, I do this
var trial = { type: jsPsychExternalHtml, url: '../src/stimulus.html', execute_script: true, force_refresh:true, cont_btn: "submit", on_start: function(){ localStorage.setItem("graphType","scatter") } }
... and a script on stimulus.html reads the local storage, and uses that value to draw that type of graph.
BUT it would be nice if I didn't need to do that, and seems fair for the stimulus.html page to have access to data, such as in:
var trial = { type: jsPsychExternalHtml, url: '../src/stimulus.html', data:{ graphType: "scatter" }, execute_script: true, force_refresh:true, cont_btn: "submit" }
I've created a modified version of the external-html plugin that creates a new html element of type
<data>
, sets an attribute called data-jspsych, and passes a JSON stringified version of trial.data. The outcome is that whatever I define in the trial data is available on the external-html page as a data attribute of a data element.My question is:
Thanks for this great tool!
Beta Was this translation helpful? Give feedback.
All reactions