gpt4 book ai didi

R Shiny 如何 "box" Shiny 页面上的简单文本

转载 作者:行者123 更新时间:2023-12-04 13:10:43 25 4
gpt4 key购买 nike

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

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,你应该寻找什么。 (;
例如,您可以从链接到 Shiny 应用程序的网页中复制并粘贴 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)
enter image description here

关于R Shiny 如何 "box" Shiny 页面上的简单文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65587869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com