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
I extensively use .rmd/.qmd documents to create reports, but also to write tutorials for workshops and lectures. Echoing code is a standard feature that helps me do this.
The problem I encounter when writing tutorials for shiny workshops, is that I cannot find a (good1) way to echo the server-side code. I would like some way to easily include server-side code for inline shiny widgets in a rendered markdown document (obviously using the shiny runtime).
The best case scenario would be an embedded version of the code view as used in shiny's 'showcase' mode.
Realistically, just echoing server context chunks as a plain code block would already be a huge quality of live upgrade for me.
I've searched the rmarkdown and shiny documentation without any results, and a broader search only found vague answers explaining that this is not possible "because the server code runs in a different context"2. I suspect that answer misunderstood the question, because I don't understand why a server context code block could not be echoed during rendering, just as any other code block? I understand the outputs (and reactive updates for the showcase) are not available during render, but the code itself is?
In addition, given that a shiny document requires a backing shiny server anyway, why could 'live' content not be injected at runtime, just as regular inline shiny widgets are? Given the motivation, time, and resources, it should be theoretically possible to render and embed a special version of shiny's showcase mode for inline server-side code, no?
If there are intricacies of the render pipeline that make this impossible, could you (point me to resources that) explain this more in depth?
Footnotes
I've resorted to including a duplicate of the server code in a plain code block, but that's ugly and inconvenient. ↩
I can't seem to find the stack overflow question where this was referenced anymore, apologies. ↩
The text was updated successfully, but these errors were encountered:
You should be able to echo the server code by setting echo = TRUE. Here's an example using the new Shiny Rmd template:
---title: "Issue 2524"output: html_documentruntime: shiny---## Inputs and Outputs
You can embed Shiny inputs and outputs in your document. Outputs are automatically updated whenever inputs change. This demonstrates how a standard R plot can be made interactive by wrapping it in the Shiny `renderPlot` function. The `selectInput` and `sliderInput` functions create the input widgets used to drive the plot.
```{r eruptions, echo = FALSE}
inputPanel( selectInput("n_breaks", label = "Number of bins:", choices = c(10, 20, 35, 50), selected = 20), sliderInput("bw_adjust", label = "Bandwidth adjustment:", min = 0.2, max = 2, value = 1, step = 0.2))``````{r eruptions-server, echo = TRUE, context = "server"}
renderPlot({ hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks), xlab = "Duration (minutes)", main = "Geyser eruption duration") dens <- density(faithful$eruptions, adjust = input$bw_adjust) lines(dens, col = "blue")})```
I extensively use .rmd/.qmd documents to create reports, but also to write tutorials for workshops and lectures. Echoing code is a standard feature that helps me do this.
The problem I encounter when writing tutorials for shiny workshops, is that I cannot find a (good1) way to echo the server-side code. I would like some way to easily include server-side code for inline shiny widgets in a rendered markdown document (obviously using the shiny runtime).
The best case scenario would be an embedded version of the code view as used in shiny's 'showcase' mode.
Realistically, just echoing server context chunks as a plain code block would already be a huge quality of live upgrade for me.
I've searched the rmarkdown and shiny documentation without any results, and a broader search only found vague answers explaining that this is not possible "because the server code runs in a different context"2. I suspect that answer misunderstood the question, because I don't understand why a server context code block could not be echoed during rendering, just as any other code block? I understand the outputs (and reactive updates for the showcase) are not available during render, but the code itself is?
In addition, given that a shiny document requires a backing shiny server anyway, why could 'live' content not be injected at runtime, just as regular inline shiny widgets are? Given the motivation, time, and resources, it should be theoretically possible to render and embed a special version of shiny's showcase mode for inline server-side code, no?
If there are intricacies of the render pipeline that make this impossible, could you (point me to resources that) explain this more in depth?
Footnotes
I've resorted to including a duplicate of the server code in a plain code block, but that's ugly and inconvenient. ↩
I can't seem to find the stack overflow question where this was referenced anymore, apologies. ↩
The text was updated successfully, but these errors were encountered: