r - 在 Shiny 中保存多个 TinyMCE 的内容
问题描述
我在闪亮中使用了两个 tinyMCE 实例。我想使用单个操作按钮将这两个实例的内容保存为 csv 文件。我可以使用两个操作按钮,但这违背了我的目标。对 javascript 以及如何使其在 R 中工作并不是很好。我能够获取一些代码来保存第一个实例的输出。以下是一个工作示例。
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidRow(
titlePanel("tinyMCE Shiny"),
br(),
column(width=6,
tags$script(src='https://cloud.tinymce.com/stable/tinymce.min.js'),
tags$form(method="post",
tags$textarea(id="textHolder1"),
tags$textarea(id="textHolder2")
),
br(),
actionButton("fetch", "Get Results!", icon=icon("lightbulb-o"),class="btn-primary",
onclick = "Shiny.onInputChange('typedText', tinyMCE.get('textHolder1').getContent());"),
tags$script("
tinymce.init({
selector:'#textHolder1',
theme: 'modern',
height: 500,
plugins: ['advlist autolink link image lists charmap preview hr table','wordcount',],
menubar: true,
toolbar: 'undo redo | bold italic | bullist | link | image ',
});"),
tags$script("
tinymce.init({
selector:'#textHolder2',
theme: 'modern',
height: 500,
plugins: ['advlist autolink link image lists charmap preview hr table','wordcount',],
menubar: true,
toolbar: 'undo redo | bold italic | bullist | link | image ',
});")
),
column(width=6,
tags$style(HTML('pre {height:240px;}')),
tags$label(`for`="rawText", "Raw String"),
hr(),
tags$pre(textOutput("rawText")),
br(),
tags$label(`for`="htmlText", "HTML Version"),
hr(),
tags$pre(htmlOutput("htmlText"))
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$htmlText <- renderUI({
req(input$typedText)
HTML(enc2utf8(input$typedText))
})
output$rawText <- renderText({
req(input$typedText)
enc2utf8(input$typedText)
})
observeEvent(input$fetch,{
j <- data.frame("t"= HTML(enc2utf8(input$typedText)))
write.csv(j,"test.csv")
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决方案
您可以连接来自两个文本的输入 onclick
-
actionButton("fetch", "Get Results!", icon=icon("lightbulb-o"),class="btn-primary",
onclick = "Shiny.onInputChange('typedText', tinyMCE.get('textHolder1').getContent() + tinyMCE.get('textHolder2').getContent());")
完整的应用程序代码 -
ui <- fluidRow(
titlePanel("tinyMCE Shiny"),
br(),
column(width=6,
tags$script(src='https://cloud.tinymce.com/stable/tinymce.min.js'),
tags$form(method="post",
tags$textarea(id="textHolder1"),
tags$textarea(id="textHolder2")
),
br(),
actionButton("fetch", "Get Results!", icon=icon("lightbulb-o"),class="btn-primary",
onclick = "Shiny.onInputChange('typedText', tinyMCE.get('textHolder1').getContent() + tinyMCE.get('textHolder2').getContent());"),
tags$script("
tinymce.init({
selector:'#textHolder1',
theme: 'modern',
height: 500,
plugins: ['advlist autolink link image lists charmap preview hr table','wordcount',],
menubar: true,
toolbar: 'undo redo | bold italic | bullist | link | image ',
});"),
tags$script("
tinymce.init({
selector:'#textHolder2',
theme: 'modern',
height: 500,
plugins: ['advlist autolink link image lists charmap preview hr table','wordcount',],
menubar: true,
toolbar: 'undo redo | bold italic | bullist | link | image ',
});")
),
column(width=6,
tags$style(HTML('pre {height:240px;}')),
tags$label(`for`="rawText", "Raw String"),
hr(),
tags$pre(textOutput("rawText")),
br(),
tags$label(`for`="htmlText", "HTML Version"),
hr(),
tags$pre(htmlOutput("htmlText"))
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$htmlText <- renderUI({
req(input$typedText)
HTML(enc2utf8(input$typedText))
})
output$rawText <- renderText({
req(input$typedText)
enc2utf8(input$typedText)
})
observeEvent(input$fetch,{
j <- data.frame(t = HTML(enc2utf8(input$typedText)))
write.csv(j,"test.csv")
})
}
# Run the application
shinyApp(ui = ui, server = server)
推荐阅读
- c - CLion Mac EOF 可能的错误
- c# - 获得异常“无法访问已处置的对象”。在同一个 mvc 页面上执行第二个操作时
- python - 向 Django 模型添加代码和方法会破坏它
- c# - 列表
无法映射 - java - java.lang.NoClassDefFoundError:无法初始化类 org.hibernate.validator.internal.engine.ConfigurationImpl
- swift - 在 SiriShortcut 中刷新意图字符串
- javascript - 如何在完整日历中设置开始和结束日期的开始和结束时间
- php - 在 Woocommerce 3 中获取最后一次订阅续订订单信息
- join - KSQL 加入两个以上的流
- python - Pygame背景蒙版碰撞不起作用