是否可以允许用户将自定义的html/css作为输入按钮更改与R Shiny应用程序中类似于常见的文本编辑器(例如Word/Excel)的文本?

发布于 2025-01-26 15:17:07 字数 933 浏览 5 评论 0原文

因此,我有一个简单的闪亮应用程序,它将文本作为输入并输出。

但是我的目标是使我的用户更容易以易于使用的方式自定义该文本的字体和格式化。

这是应用程序的屏幕截图(下图)。我可以输入HTML代码来更改格式,但我的用户不知道HTML或CSS。

我的用户有没有一种简单的方法,可以使用一些可以通过输入传递的基本格式的UI?有点像这样吗?

这是我的应用程序代码:

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    textAreaInput("text", label = HTML(paste0("Enter Text Here")), value = HTML(paste0("HTML ELEMENTS CAN BE USED"))),
  mainPanel(
    uiOutput("value"))
  )
)

server <- function(input, output) {
  output$value <- reactive({
    shiny::HTML(paste0(input$text)) 
  })
}

shinyApp(ui, server)



So I have a simple shiny app that takes text as an input and outputs it.

But my goal is to make it easier for my users to be able to customize the font and formatting of this text in an easy to use way.

Here is a screenshot of the app (below). I can enter HTML code to change the formatting but my users do not know HTML or CSS.

enter image description here

Is there an easy way for my users to be able to have a little UI with basic formatting that can be passed through the input? Kind of like this?

enter image description here

Here is my app code:

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    textAreaInput("text", label = HTML(paste0("Enter Text Here")), value = HTML(paste0("HTML ELEMENTS CAN BE USED"))),
  mainPanel(
    uiOutput("value"))
  )
)

server <- function(input, output) {
  output$value <- reactive({
    shiny::HTML(paste0(input$text)) 
  })
}

shinyApp(ui, server)



如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摘星┃星的人 2025-02-02 15:17:07

您可以使用JavaScript库 suneditor

library(shiny)

js <- '
$(document).ready(function(){
  const editor = SUNEDITOR.create(document.getElementById("editor"), {});
});
'

ui <- fluidPage(
  tags$head(
    tags$link(rel="stylesheet", href = "https://cdn.jsdelivr.net/npm/suneditor@latest/dist/css/suneditor.min.css"),
    tags$script(src = "https://cdn.jsdelivr.net/npm/suneditor@latest/dist/suneditor.min.js"),
    tags$script(HTML(js))
  ),
  br(),
  tags$textarea(id = "editor", class = "sun-editor-editable", cols = 80)
)

server <- function(input, output, session){
  
}

shinyApp(ui, server)

”

You can use the JavaScript library SunEditor

library(shiny)

js <- '
$(document).ready(function(){
  const editor = SUNEDITOR.create(document.getElementById("editor"), {});
});
'

ui <- fluidPage(
  tags$head(
    tags$link(rel="stylesheet", href = "https://cdn.jsdelivr.net/npm/suneditor@latest/dist/css/suneditor.min.css"),
    tags$script(src = "https://cdn.jsdelivr.net/npm/suneditor@latest/dist/suneditor.min.js"),
    tags$script(HTML(js))
  ),
  br(),
  tags$textarea(id = "editor", class = "sun-editor-editable", cols = 80)
)

server <- function(input, output, session){
  
}

shinyApp(ui, server)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文