TheoreticalEcology / machinelearning

Teaching Material for a Machine Learning course with Keras and Tensorflow in R
https://theoreticalecology.github.io/machinelearning/
Other
16 stars 4 forks source link

questionnaire #18

Closed MaximilianPi closed 3 years ago

MaximilianPi commented 3 years ago

Hi @Meier-Matthias,

the code for the questionnaire looks very nice (and well documented) but I don't know how to get it work within a bookdown:

I embedded the questionnaire as a html chunk in a Rmarkdown but the questionnaire doesn't show up in the compiled book.

```{=html}

<script src="script.js">
makeMultipleChoiceForm(
        'How much is the fish?',
        'text',
        [
            {
                'answer':'123',
                'correct':true,
                'explanationIfSelected':'Right guess.',
                'explanationIfNotSelected':'Wrong guess.',
                'explanationGeneral':''
            },
            {
                'answer':'321',
                'correct':false,
                'explanationIfSelected':'Wrong guess.',
                'explanationIfNotSelected':'',
                'explanationGeneral':''
            }
        ],
        'comment text'
    );</script>

#```

PS: there is a minimal bookdown example (https://github.com/yihui/bookdown-minimal) for testing.

Meier-Matthias commented 3 years ago

I think it's the path to the questionnaire. Put it in explicitly or maybe we use an uploaded version of that and refer to it.

MaximilianPi commented 3 years ago

No, the path (you mean the path to the saved script, right? ('script.js')) is correct because it is checked during compilation which will be aborted with a wrong path... so I assume that the script is correctly loaded and the makeMultipleChoiceForm function is called but nothing shows up.

Meier-Matthias commented 3 years ago

Well, I saw 2 errors. You have to specify the right path (the name of the script is "multipleChoice" though). And you have to use 2 script tags. One to include the script and one for writing your own content.

Here is a (at least for me) working example:


<script src="./scripts/multipleChoice.js"></script>
<script>
makeMultipleChoiceForm(
        'How much is the fish?',
        'text',
        [
            {
                'answer':'123',
                'correct':true,
                'explanationIfSelected':'Right guess.',
                'explanationIfNotSelected':'Wrong guess.',
                'explanationGeneral':''
            },
            {
                'answer':'321',
                'correct':false,
                'explanationIfSelected':'Wrong guess.',
                'explanationIfNotSelected':'',
                'explanationGeneral':''
            }
        ],
        'comment text'
    );
</script>
MaximilianPi commented 3 years ago

ah perfect! It is working with two script tags, thanks!