1

我想在 Shiny 中的一行中添加一个表格,但我找不到这样做的方法。

图 1

我知道 Shiny 中有 HTML 标签,例如strong将单词加粗,small使它们更小......甚至blockquote添加引号块。但是我没有找到一个添加一个列表。

有谁知道该怎么做?

可重现的代码:

library(shiny)
ui = pageWithSidebar(
  headerPanel("My app"),
  sidebarPanel(
    
  ),
  mainPanel(
            htmlOutput("text")
  )
)
server = function(input, output) {
  output$text <- renderUI({
    str1 <- strong("This is the first line in bold:")
    str2 <- em("This is the second line in italics and with one tabulation")
                
    HTML(paste(str1, str2, sep = '<br/>'))
    
  })
}

shinyApp(ui,server)
4

2 回答 2

1

您可以只使用 html 代码而不是闪亮的 r 标签来做到这一点:

library(shiny)
ui = pageWithSidebar(
  headerPanel("My app"),
  sidebarPanel(
    
  ),
  mainPanel(
    htmlOutput("text")
  )
)
server = function(input, output) {
  output$text <- renderUI({
    str1 <- "<p><strong>This is the first line in bold:</strong></p>"
    str2 <- "<p style='text-indent: 45px'><em>This is the second line in italics and with one tabulation</em></p>"
    
    HTML(paste(str1, str2, sep = ''))
    
  })
}

shinyApp(ui,server)

除非我误解了你想要做什么。

在此处输入图像描述

于 2022-01-12T18:00:22.850 回答
1

您可以为每个闪亮标签添加样式属性:

library(shiny)
ui = pageWithSidebar(
  headerPanel("My app"),
  sidebarPanel(),
  mainPanel(
    htmlOutput("text")
  )
)
server = function(input, output) {
  output$text <- renderUI({
    tag1 <- p(strong("This is the first line in bold:"))
    tag2 <- p(em("This is the second line in italics and with one tabulation"), style = "text-indent: 1em;")
    HTML(paste(tag1, tag2, sep = '<br/>'))
  })
}

shinyApp(ui,server)

结果

于 2022-01-13T07:05:09.857 回答