Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(shinyjs)
- if (interactive()) {
- ui <- shinyUI(
- fluidPage(
- useShinyjs(),
- tags$head(tags$title("Title"),
- tags$link(rel = "stylesheet", href = "codemirror.css"),
- tags$link(rel = "stylesheet", href = "cobalt.css"),
- tags$script(src = "codemirror.js"),
- tags$script(src = "r.js")
- ),
- actionButton("btn1","Click to see code"),
- uiOutput(outputId = "textStringToDisplay")))
- server <- function(input, output){
- output$textStringToDisplay <- renderUI(
- tags$textarea(id="textBox", name = "Feedback", paste0(sample(letters,15),collapse = "")))
- ButtonPressCounter <- 0
- observeEvent(input$btn1,
- {
- ButtonPressCounter <<- ButtonPressCounter + 1 # Need it to happen only once
- if(ButtonPressCounter <= 1){
- shinyjs::runjs(
- 'var editorR = CodeMirror.fromTextArea(textBox, {
- mode: "r",
- lineNumbers: true,
- smartindent: true});
- editorR.setOption("theme", "cobalt");
- editorR.setSize("100%","100%");')
- }
- })
- }
- shinyApp(ui = ui, server = server) }
Add Comment
Please, Sign In to add comment