R闪亮如何在闪亮的页面上“装箱”简单的文本

Ang*_*elo 11 r shiny shinydashboard shinyapps

我正在使用文档https://shiny.rstudio.com/tutorial/writing-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.")
    )
  )
)
Run Code Online (Sandbox Code Playgroud)

我的目标是采用这些段落中的任何一段,比如说最后一个,并将其显示在一个盒子内,就像我们在这里看到的一样:http: //www.sthda.com/english/articles/40-regression- Analysis/168-multiple-linear-regression-in-r/
其中写着“library(tidyverse)”,该段落位于具有不同背景颜色的框内。有谁知道我怎样才能实现这一目标?我对 HTML 不太了解,因此我面临着困难。谢谢

ste*_*fan 23

你应该寻找的不是 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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述