2

I would like to use R shiny to output dynamic code chunks with the syntax highlighted in Python/Mathematica/C++/Julia/R. Does anyone know how to do this?

For example, the following generates code to produce a normal random variable in Python for a user-determined mean (with std. deviation 1).

library(shiny)
runApp(list(
  ui = bootstrapPage(
    sliderInput("mu", "Mean", min=-30, max=30, value=0, step=0.2),
    uiOutput('chunk')
  ),
  server = function(input, output) {
    output$chunk <- renderUI({ 
       HTML(markdown::markdownToHTML(text=paste0("```{python}",
                                     "\n numpy.random.normal(", input$mu, ", 1)"), 
                                     options=c("highlight_code"))) })
    }
))

I wrote a question previously here which wasn't clear that I wanted to be able to highlight code from other languages than R, and so I am reposting one specific to Python.

ben18785
  • 356
  • 1
  • 5
  • 15

0 Answers0