首页 > 解决方案 > 在 Shiny 的 UI 部分中的文本内添加了空格

问题描述

我注意到当我使用时会出现一个空格em()strong()并且显然,textOutput()当它们p()位于 ui 的标签内时,或者即使它们是松散的文本。这是我的代码:

ui <- fluidPage(
  p("This is ", strong("bold"), ", and this is ", em("italic"), "."),
  br(),
  "Again, this is ", strong("bold"), ", and this is ", em("italic"), "."
)

服务器上什么都没有。这个textOutput()例子有点长,它没有显示任何新的东西,所以我把它省略了。

输出是这样的:

这是粗体,这是斜体

同样,这是粗体,这是斜体

如您所见,逗号和句点由空格分隔。这真的很烦人——毕竟,标点符号在“正确的”英语中没有这个,这是我想在我的 Shiny App 中保留的东西。

标签: rshiny

解决方案


你可以使用.noWS参数。

library(shiny)

ui <- fluidPage(
  p("This is ", strong("bold", .noWS = c("after")), ", and this is ", em("italic"), "."),
  br(),
  "Again, this is ", strong("bold", .noWS = c("after")), ", and this is ", em("italic"), "."
)

server <- function(input, output) {}

shinyApp(ui = ui, server = server)

结果:

This is bold, and this is italic .

Again, this is bold, and this is italic .

推荐阅读