learnrhash icon indicating copy to clipboard operation
learnrhash copied to clipboard

Option to save answers in into rds file directly?

Open davidkane9 opened this issue 4 years ago • 0 comments

Have you considered providing an option which would allow users to save their answers directly into an rds file? This avoids the complexity of dealing with hashes directly. We are implemented such an approach here:

https://github.com/PPBDS/primer.tutorials

With the key code (modified from learnrhash) looks like:

submission_server <- function(input, output) {
  p = parent.frame()
  check_server_context(p)

  # Evaluate in parent frame to get input, output, and session
  
  local({
    encoded_txt = shiny::eventReactive(
      input$hash_generate,
      {
        objs = learnr:::get_all_state_objects(session)
        objs = learnr:::submissions_from_state_objects(objs)

        encode_obj(objs)
      }
    )

    output$downloadData <- shiny::downloadHandler(
      filename = "tutorial_responses.rds",
      content = function(file) {
        responses <- encoded_txt()
        readr::write_rds(responses, file)
      }
    )

  }, envir = p)
}

This worked well for us this semester. Students just uploaded the file directly into Canvas. But, first, we have no interest in maintaining our own version and, second, we can't figure out how to have the output filename be something different for each tutorial.

Sure hope that learnhash (or even learnr itself) provides this functionality directly someday.

davidkane9 avatar Dec 11 '20 21:12 davidkane9