【问题标题】:R shiny how to "box" a simple text on a shiny pageR闪亮如何在闪亮的页面上“装箱”一个简单的文本
【发布时间】:2021-04-11 17:35:40
【问题描述】:

我正在使用文档https://shiny.rstudio.com/tutorial/written-tutorial/lesson2/,更准确地说是使用以下代码向我的闪亮页面添加一个简单的段落:

ui <- fluidPage(
  titlePanel("My Shiny App"),
  sidebarLayout(
    sidebarPanel(),
    mainPanel(
      p("p creates a paragraph of text."),
      p("A new p() command starts a new paragraph. Supply a style attribute to change the format of the entire paragraph.", style = "font-family: 'times'; font-si16pt"),
      strong("strong() makes bold text."),
      em("em() creates italicized (i.e, emphasized) text."),
      br(),
      code("code displays your text similar to computer code"),
      div("div creates segments of text with a similar style. This division of text is all blue because I passed the argument 'style = color:blue' to div", style = "color:blue"),
      br(),
      p("span does the same thing as div, but it works with",
        span("groups of words", style = "color:blue"),
        "that appear inside a paragraph.")
    )
  )
)

我的目标是获取这些段落中的任何一段,比如说最后一段,并像在一个盒子里一样显示它,就像我们在这里看到的一样: http://www.sthda.com/english/articles/40-regression-analysis/168-multiple-linear-regression-in-r/
在它说“图书馆(tidyverse)”的地方,这一段是在一个不同背景颜色的盒子里。 有谁知道我怎么能做到这一点? 我对 HTML 不太了解,因此我面临着艰难的时期。 谢谢

【问题讨论】:

  • 或许答案here可以帮到你。

标签: r shiny shinydashboard shinyapps


【解决方案1】:

您应该寻找的不是 HTML,而是 CSS。 (;

例如,您可以从链接的网页中复制 CSS 样式规则并将其粘贴到闪亮的应用程序中(不是推荐的方式,但快速而肮脏),以更改 code 标记的外观,如下所示:

library(shiny)

ui <- fluidPage(
    tags$head(
        tags$style(HTML("
            code {
                display:block;
                padding:9.5px;
                margin:0 0 10px;
                margin-top:10px;
                font-size:13px;
                line-height:20px;
                word-break:break-all;
                word-wrap:break-word;
                white-space:pre-wrap;
                background-color:#F5F5F5;
                border:1px solid rgba(0,0,0,0.15);
                border-radius:4px; 
                font-family:monospace;
            }"))),
    titlePanel("My Shiny App"),
    sidebarLayout(
        sidebarPanel(),
        mainPanel(
            p("p creates a paragraph of text."),
            p("A new p() command starts a new paragraph. Supply a style attribute to change the format of the entire paragraph.", style = "font-family: 'times'; font-si16pt"),
            strong("strong() makes bold text."),
            em("em() creates italicized (i.e, emphasized) text."),
            br(),
            code("code displays your text similar to computer code"),
            div("div creates segments of text with a similar style. This division of text is all blue because I passed the argument 'style = color:blue' to div", style = "color:blue"),
            br(),
            p("span does the same thing as div, but it works with",
              span("groups of words", style = "color:blue"),
              "that appear inside a paragraph.")
        )
    )
)

server <- function(input, output) {

}

shinyApp(ui = ui, server = server)

【讨论】:

  • 谢谢斯特凡!
猜你喜欢
  • 2020-10-25
  • 1970-01-01
  • 2014-01-01
  • 2021-02-26
  • 2019-12-08
  • 2019-05-07
  • 1970-01-01
  • 2017-02-04
  • 1970-01-01
相关资源
最近更新 更多