You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has come up more than once and is likely fraught with edge cases. But we could provide something a little more user-friendly, based on my answer in the discussion here.
It is possible to update the text in a code box dynamically from the Shiny server that runs the learnr tutorial, which means that you could in theory use the query parameters to initialize the code boxes. There are probably more than a few edge cases you'd want to think through (or end up running into).
The process for updating an exercise code box from the server isn't very straightforward and it requires writing a little bit of JavaScript. I'd recommend taking a look at my answer to a similar question on Posit Community.
First, you'd include a chunk of JavaScript in your learnr document.
```{js echo=FALSE}
//// A custom Shiny message handler that updates the code in any exercise// From R you'll send a list(label = "exercise-chunk-label", code = "new code for editor"))//Shiny.addCustomMessageHandler('set-exercise-code', function(x) { var el = $(`.tutorial-exercise[data-label="${x.label}"] .tutorial-exercise-code-editor`) var exerciseInput = Shiny.inputBindings.bindingNames["tutorial.exerciseInput"].binding exerciseInput.setValue(el, {code: x.code})})```
Then, include this function in your setup chunk or in a chunk with context = "server":
This has come up more than once and is likely fraught with edge cases. But we could provide something a little more user-friendly, based on my answer in the discussion here.
It is possible to update the text in a code box dynamically from the Shiny server that runs the learnr tutorial, which means that you could in theory use the query parameters to initialize the code boxes. There are probably more than a few edge cases you'd want to think through (or end up running into).
The process for updating an exercise code box from the server isn't very straightforward and it requires writing a little bit of JavaScript. I'd recommend taking a look at my answer to a similar question on Posit Community.
First, you'd include a chunk of JavaScript in your learnr document.
Then, include this function in your setup chunk or in a chunk with
context = "server"
:which you can then use to update an exercise using the label of its chunk:
I hope that helps! If you do figure out how to make this work, we'd love to see what you come up with!
The text was updated successfully, but these errors were encountered: