I made a slight variation of what your code does by adding some Javascript.
import prodigy
@prodigy.recipe("checkbox")
def checkbox():
template = """
<form>
<div>
<p>{{text}}</p>
<label onclick="update()">check this box!</label>
<input class="checkbox" type='checkbox' value='{{n}}' onchange="update()">
</div>
</form>
"""
javascript = """
function update(){
let checked = document.querySelector(".checkbox").checked;
prodigy.update({"checked": checked})
console.log("update ran");
}
document.addEventListener('prodigyanswer', event => {
const {answer, task} = event.detail;
console.log(answer);
console.log(task);
})
"""
return {
"dataset": "checkbox-demo",
"view_id": "html",
"stream": ({'text': f"This is example {i}", "n": i} for i in range(1000)),
"config": {
"html_template": template,
"javascript": javascript,
},
}
I can this recipe via:
python -m prodigy checkbox -F recipe.py
And this gives me this interface:
When you click the checkbox, you should see that the console logs "update ran". When you hit A to accept you'll also see a log appear of the answer and the task. This is what the task looks like when I check the checkbox.
{
checked: true
n: 0
text: "This is example 0"
_input_hash: 780466941
_task_hash: -621577502
_view_id: "HTML"
}
You'll notice that checked
is set to true
. I can also confirm, after hitting the save button, that this is stored in Prodigy.
python -m prodigy db-out checkbox-demo
# {"text":"This is example 0","n":0,"_input_hash":780466941,"_task_hash":-621577502,"_view_id":"html","checked":true,"answer":"accept","_timestamp":1656571196}
Does this suffice?