# [editors] utils functions
#' r_onlyread_editor
#'
#' @param outputId output id
#' @param value code to print
r_onlyread_editor <- function(outputId, value) {
onlyread_editor(outputId = outputId, value = value, mode = "r")
}
#' sql_onlyread_editor
#'
#' @param outputId output id
#' @param value code to print
sql_onlyread_editor <- function(outputId, value) {
onlyread_editor(outputId = outputId, value = value, mode = "sql")
}
#' r_editable_editor
#'
#' @param outputId output id
#' @param value code to print
#' @param comment add a comment at the first line
#' @importFrom shiny HTML
r_editable_editor <- function(outputId, value, comment) {
if (!missing(comment) & !is.null(comment)) {
value <- HTML(paste0("# ", comment, "\n", value))
}
editable_editor(
outputId = outputId,
value = value,
mode = "r",
placeholder = "R editor"
)
}
#' sql_editable_editor
#'
#' @param outputId output id
#' @param value code to print
#' @param comment add a comment at the first line
#' @importFrom shiny HTML
sql_editable_editor <- function(outputId, value, comment) {
if (!missing(comment) & !is.null(comment)) {
value <- HTML(paste0("-- ", comment, "\n", value))
}
editable_editor(
outputId = outputId,
value = value,
mode = "sql",
placeholder = "SQL editor"
)
}
#' onlyread_editor
#'
#' @param outputId output id
#' @param mode editor mode
#' @param value code to print
#' @importFrom shinyAce aceEditor
onlyread_editor <- function(outputId, mode, value) {
aceEditor(
outputId = outputId,
mode = mode,
value = value,
theme = "tomorrow",
readOnly = TRUE,
showLineNumbers = FALSE,
highlightActiveLine = FALSE,
height = "120px"
)
}
#' editable_editor
#'
#' @param outputId output id
#' @param mode editor mode
#' @param value code to print
#' @param placeholder placeholder
#' @importFrom shinyAce aceEditor
editable_editor <- function(outputId, mode, value, placeholder) {
aceEditor(
outputId = outputId,
mode = mode,
value = value,
placeholder = placeholder,
theme = "cobalt",
readOnly = FALSE,
showLineNumbers = TRUE,
highlightActiveLine = TRUE,
height = "120px"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.