|
source('init.R') |
|
|
|
library(shiny) |
|
library(shinythemes) |
|
library(shinyAce) |
|
library(shinyjs) |
|
|
|
renderLogEntry <- function(entry){ |
|
paste0(entry, " - ", date()) |
|
} |
|
|
|
|
|
withConsoleRedirect <- function(containerId, expr) { |
|
txt <- capture.output(results <- expr, type = "output") |
|
if (length(txt) > 0) { |
|
appendTabsetPanel(session, "console", tabPanel("Console", verbatimTextOutput(paste0(txt, "\n")))) |
|
} |
|
results |
|
} |
|
|
|
|
|
|
|
shinyServer(function(input, output, session) { |
|
|
|
|
|
hide("sidebar") |
|
observeEvent(input$theme_button, { |
|
showModal(modalDialog( |
|
title = "Elige un tema", |
|
shinythemes::themeSelector() |
|
)) |
|
}) |
|
|
|
|
|
observe({ |
|
updateAceEditor( |
|
session, |
|
"rmd", |
|
theme = input$theme_code |
|
) |
|
}) |
|
|
|
output$knitDoc <- renderUI({ |
|
input$eval |
|
HTML(knitr::knit2html(text = isolate(input$rmd), quiet = TRUE)) |
|
}) |
|
|
|
|
|
observeEvent(input$clear,{ |
|
updateAceEditor(session,'rmd',value = '') |
|
}) |
|
|
|
|
|
observeEvent(input$open_chunk,{ |
|
delay(3000,{ |
|
updateAceEditor(session,'rmd',value = paste(isolate(input$rmd),"\n```{r}\n\n```\n",sep = '')) |
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
observeEvent(input$rmd_open_chunk, { |
|
|
|
delay(3000, { |
|
|
|
old_val <- isolate(input$rmd) |
|
|
|
|
|
new_chunk <- "\n```{r}\n\n```\n" |
|
|
|
|
|
new_val <- paste(old_val, new_chunk, sep = "") |
|
|
|
|
|
updateAceEditor(session, 'rmd', value = new_val) |
|
}) |
|
|
|
}) |
|
|
|
|
|
observeEvent(input$rmd_help_key, { |
|
|
|
showModal(modalDialog( |
|
title = "Help Menu", |
|
h2("Hot-Keys"), |
|
"Use the following hot-keys:", |
|
tags$ul( |
|
tags$li("Ctrl-Alt-I: Open Chunk"), |
|
tags$li("Ctrl-F: Buscar y Reemplazar"), |
|
tags$li("F1: Help Menu"), |
|
tags$li("Ctrl-Z: Undo"), |
|
tags$li("Ctrl-Y: Redo"), |
|
) |
|
)) |
|
}) |
|
|
|
output$save_code <- downloadHandler( |
|
filename = function() { |
|
paste("code-", Sys.Date(), ".Rmd", sep="") |
|
}, |
|
content = function(file) { |
|
writeLines(input$rmd, file) |
|
} |
|
) |
|
|
|
output$save_knit <- downloadHandler( |
|
filename = function() { |
|
paste("knit-", Sys.Date(), ".html", sep="") |
|
}, |
|
content = function(file) { |
|
|
|
tmp_file <- tempfile(fileext = ".Rmd") |
|
writeLines(input$rmd, tmp_file) |
|
|
|
|
|
rmarkdown::render(input = tmp_file, output_file = file, output_format = "html_document") |
|
} |
|
) |
|
|
|
observeEvent(input$toggleSidebar, { |
|
toggle("sidebar") |
|
}) |
|
}) |