是否可以具有固定宽度的verbatimTextOutput并在Shiny中更改文本行? [英] Is it possible to have fixed width verbatimTextOutput and have texts change lines in Shiny?

查看:292
本文介绍了是否可以具有固定宽度的verbatimTextOutput并在Shiny中更改文本行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用verbatimTextOutput来显示一些文本的简单应用程序.我想知道是否可以固定verbatimTextOutput的宽度并让文本输出更改行吗?

I have a simple app that uses verbatimTextOutput to display some texts. I am wondering if it is possible to have the width of verbatimTextOutput to be fixed and have the text output change lines?

请参见此示例( https://yuchenw.shinyapps.io/verbatimtext_bookmark/) .我还附上了下面的代码.

Please see this example (https://yuchenw.shinyapps.io/verbatimtext_bookmark/). I also attached the code below.

如所附的屏幕截图所示,当字符串很长时,verbatimTextOutput不会显示所有文本.相反,verbatimTextOutput会在底部显示滚动条.

As the attached screenshot shows, when the string is very long, the verbatimTextOutput would not show all the text. Instead, the verbatimTextOutput would show a scroll bar at the bottom.

但是,我希望verbatimTextOutput的底部没有滚动条.我还需要当文本较长时,更改行以适合verbatimTextOutput.以下面为例,即单击书签按钮.我们可以看到,冗长的URL更改了行,并且输出的底部没有滚动条.如果书签按钮可以做到这一点,希望我也可以使verbatimTextOutput显示书签的相似特征和外观.

However, I hope there will be no scroll bar at the bottom of the verbatimTextOutput. I also need that when the texts are long, change lines to fit in the verbatimTextOutput. Taking the following as an example, which is by clicking the bookmark button. We can see that this lengthy URL change lines, and there is no scroll bar at the bottom of the output. If the bookmark button can do that, I hope I can also make the verbatimTextOutput show similar characteristics and appearance of the bookmark.

如有任何疑问,请告诉我.

Please let me know if you have any questions.

代码

library(shiny)


ui <- function(request){
  fluidPage(
    column(
      width = 6,
      textInput(inputId = "txt", label = "Type in some texts",
                value = paste0(rep(letters, 10), collapse = "")),
      strong("Show the texts"),
      verbatimTextOutput("txt_out"),
      br(),
      bookmarkButton()
    )
  )
}
server <- function(input, output, session){
  output$txt_out <- renderText({
    input$txt
  })
}
enableBookmarking("url")
shinyApp(ui, server)

推荐答案

请尝试以下CSS:

library(shiny)

ui <- function(request){
  fluidPage(
    tags$style(type='text/css', '#txt_out {white-space: pre-wrap;}'),
    column(
      width = 6,
      textInput(inputId = "txt", label = "Type in some texts",
                value = paste0(rep(letters, 10), collapse = "")),
      strong("Show the texts"),
      verbatimTextOutput("txt_out"),
      br(),
      bookmarkButton()
    )
  )
}
server <- function(input, output, session){
  output$txt_out <- renderText({
    input$txt
  })
}
enableBookmarking("url")
shinyApp(ui, server)

这篇关于是否可以具有固定宽度的verbatimTextOutput并在Shiny中更改文本行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆