【问题标题】:verbatimTextOutput() not displaying textverbatimTextOutput()不显示文本
【发布时间】:2021-09-15 14:08:07
【问题描述】:

示例如下。我想通过 UI 部分向我的应用程序添加一个句子。不是我给verbatimTextOutput("Some Text Here \n and a new line here")打的电话:

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("Old Faithful Geyser Data"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("distPlot"),
           verbatimTextOutput("Some Text Here \n and a new line here")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

当我运行它时,我看到了这个:

一直在阅读this 的帖子,因为我希望能够在一串文本中添加带有\n 的新行,但似乎无法在应用中仅显示文本。

如何在我的应用程序中添加“Some Text Here \n and a new line here”?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    顾名思义,verbatimTextOutput 用于渲染输出。它通常与 Shiny 服务器文件中的renderPrint 一起使用。即在server:

    output[["mytext"]] <- renderPrint({
      "Some Text Here \n and a new line here"
    })
    

    ui:

    verbatimTextOutput("mytext")
    

    但由于您不需要响应式文本,您可以简单地在 ui 中使用 p 标记(server 中没有任何内容:

    tags$p("Some Text Here \n and a new line here")
    

    如果换行不起作用(我没试过),你可以试试:

    tags$p("Some Text Here", br(), "and a new line here")
    

    HTML("Some Text Here <br> and a new line here")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 2014-02-26
      • 2019-03-27
      • 2017-04-24
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多