Guest User

Untitled

a guest
Dec 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. library(shiny)
  2. library(shinyjs)
  3.  
  4. if (interactive()) {
  5. ui <- shinyUI(
  6. fluidPage(
  7. useShinyjs(),
  8. tags$head(tags$title("Title"),
  9. tags$link(rel = "stylesheet", href = "codemirror.css"),
  10. tags$link(rel = "stylesheet", href = "cobalt.css"),
  11. tags$script(src = "codemirror.js"),
  12. tags$script(src = "r.js")
  13. ),
  14. actionButton("btn1","Click to see code"),
  15. uiOutput(outputId = "textStringToDisplay")))
  16. server <- function(input, output){
  17. output$textStringToDisplay <- renderUI(
  18. tags$textarea(id="textBox", name = "Feedback", paste0(sample(letters,15),collapse = "")))
  19.  
  20. ButtonPressCounter <- 0
  21.  
  22. observeEvent(input$btn1,
  23. {
  24. ButtonPressCounter <<- ButtonPressCounter + 1 # Need it to happen only once
  25. if(ButtonPressCounter <= 1){
  26. shinyjs::runjs(
  27. 'var editorR = CodeMirror.fromTextArea(textBox, {
  28. mode: "r",
  29. lineNumbers: true,
  30. smartindent: true});
  31. editorR.setOption("theme", "cobalt");
  32. editorR.setSize("100%","100%");')
  33. }
  34. })
  35. }
  36. shinyApp(ui = ui, server = server) }
Add Comment
Please, Sign In to add comment