【发布时间】:2017-12-07 11:11:14
【问题描述】:
我正在尝试将随机生成的字符串推送到 UI 上的文本区域。 HTML/Shiny/JS 的新手,但我知道一些基础知识。
我的最终目标是使用 CodeMirror (Whole download) 或 ShinyAce 编辑器类向 textarea 添加语法突出显示,但我无法将字符串从服务器输出到 textarea。我希望在textStringToDisplay 中推送某个 R 代码并需要语法高亮。
请将以下文件放在app.R的www文件夹中:
- codemirror.css
- cobalt.css
- codemirror.js(我找不到 此文件在 GitHub 上,请使用上面的下载链接,解压并 查看 lib 文件夹)
- r.js
如果您需要更多信息,或者我是否应该改写其中的任何部分,请告诉我。提前致谢。
library(shiny)
if (interactive()) {
ui <- shinyUI(
fluidPage(
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")
),
tags$textarea(id="textBox", name = "Feedback", textOutput(outputId = "textStringToDisplay")),
tags$script(
'var editorR = CodeMirror.fromTextArea(textBox, {
mode: "r",
lineNumbers: true,
smartindent: true
});
editorR.setOption("theme", "cobalt");
editorR.setSize("50%","100%");')))
server <- function(input, output){
output$textStringToDisplay <- renderText(paste0(sample(letters,15),collapse = ""))
}
shinyApp(ui = ui, server = server)
}
【问题讨论】:
标签: html r shiny codemirror