Renders R code with syntax highlighting using the highlight.js library.
Usage
renderRcode(
expr,
env = parent.frame(),
quoted = FALSE,
outputArgs = list(),
delay = 100
)
rcodeOutput(outputId)
Arguments
- expr
An expression to evaluate.
- env
The parent environment for the reactive expression. By default, this is the calling environment, the same as when defining an ordinary non-reactive expression. If
expr
is a quosure andquoted
isTRUE
, thenenv
is ignored.- quoted
If it is
TRUE
, then thequote()
ed value ofexpr
will be used whenexpr
is evaluated. Ifexpr
is a quosure and you would like to use its expression as a value forexpr
, then you must setquoted
toTRUE
.- outputArgs
List of additional arguments to pass to the output function.
- delay
Delay in milliseconds before syntax highlighting starts.
- outputId
Output variable to read the R code from.
Value
A render function similar to shiny::renderText()
.
Examples
if (interactive()) {
library("shiny")
ui <- fluidPage(
fluidRow(
column(
4,
textAreaInput(
"rcode_in",
label = NULL,
width = "100%", height = "300px",
value = "library('shiny')\n\nset.seed(42)\nx <- runif(10)"
)
),
column(
8,
rcodeOutput("rcode_out")
)
)
)
server <- function(input, output) {
output$rcode_out <- renderRcode({
htmltools::htmlEscape(input$rcode_in)
})
}
shinyApp(ui = ui, server = server)
}