R shiny 如何 "box" 闪亮页面上的简单文本
R shiny how to "box" a simple text on a shiny page
我正在使用文档 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/
在它写着“library(tidyverse)”的地方,这一段在一个背景颜色不同的盒子里。
有谁知道我怎么能做到这一点?
我对 HTML 了解不多,因此我正面临困难时期。
谢谢
这与 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)
我正在使用文档 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/
在它写着“library(tidyverse)”的地方,这一段在一个背景颜色不同的盒子里。
有谁知道我怎么能做到这一点?
我对 HTML 了解不多,因此我正面临困难时期。
谢谢
这与 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)