psychTestR icon indicating copy to clipboard operation
psychTestR copied to clipboard

Execute arbitrary code on resuming test session

Open sebsilas opened this issue 4 years ago • 1 comments

Hi Peter,

Would it be possible to execute some arbitrary code when a user resumes a test session? In my case, this would be to reimport some Javascript files.

The issue is that, on the one hand, if you import a bunch of Javascript files on every test page in your timeline, this puts a lot of strain on the app and performance degrades very noticeably. Hence, to solve this, you want to put all your imports on the first page of your test only. By not reimporting every page, the app runs much more smoothly and this is fine most of the time.

However, if the user rejoins the test at some random point in the timeline (resuming their test session), then the Javascript files will not be imported (since they are only imported on the first page of the test), and hence, all the JS functionality will be undefined, such that the user cannot use the test properly from that point onwards, when it relies on external JS.

Is there a way of solving this or would it require a new feature?

All the best, Seb

sebsilas avatar Nov 30 '21 15:11 sebsilas

Hi Seb,

Good idea. This is currently not customisable but it would be easy to make it customisable. You would need to alter the include_scripts function (currently located in ui.R) and make it possible to specify custom additional scripts to be included in the page. These scripts should be sourced from the opt (options) object.

Cheers Peter

pmcharrison avatar Dec 01 '21 13:12 pmcharrison