Checkbox results do not show up in output

I used the following code to create a checkbox to track errors in our documents. If I check the box, I do not see any results of the checkbox in my output.

Any thoughts on how I can

  • ensure the results show up as 1 (checked) or 0 (unchecked) in the output?
    {"view_id": "html", "html_template": "<div style='float:left;'>" +
        "<input type='checkbox' id='stt' name='stt' value='STT Error' style='margin-right:10px;' data-id='{{chat_id}}'>" +
        "<label for='stt'>STT Error</label>" +

I made a slight variation of what your code does by adding some Javascript.

import prodigy

def checkbox():
    template = """
            <label onclick="update()">check this box!</label>
            <input class="checkbox" type='checkbox' value='{{n}}' onchange="update()">
    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;
    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

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?

As a best practice, I do recommend adding checked as a key in your task stream that has a default value set to False. Javascript can be used to inject anything into the task, but it would be more consistent if it merely updates keys instead of adding new ones.