【问题标题】:renderPrint option in ShinyAppShinyApp 中的 renderPrint 选项
【发布时间】:2018-11-19 18:07:18
【问题描述】:

我在 ShinyApp 中使用renderPrint 函数来显示计算结果。结果前面带有[1],[2] 等。

有没有办法摆脱它?

另外,可以改变输出的字体吗?

【问题讨论】:

    标签: r shiny shiny-server shinyapps


    【解决方案1】:

    您可以使用renderText 代替renderPrint。或者withMathJax() 也可以是一个选项?

    要为您的应用设置样式,有多种方法可以做到这一点。你可以阅读here。在以下示例中,我将 css 直接包含在应用程序中。对于小型改编,这可能是最简单的方法,对于更复杂的应用,我会使用 css 文件并将其包含在 includeCSS("www/style.css")tags$head(tags$style("www/style.css")) 中。

    library(shiny)
    
    ui <- fluidPage(
      tags$head(
        tags$style(HTML("
                        #renderprint {
                          color: white;
                          background: blue;
                          font-family: 'Times New Roman', Times, serif;
                          font-size: 20px;
                          font-style: italic;
                        }
                        #rendertext {
                          color: blue;
                          background: orange;
                          font-family: 'Times New Roman', Times, serif;
                          font-size: 12px;
                          font-weight: bold;
                        }
                        #rendertext1 {
                          color: red;
                          background: yellow;
                          font-family: Arial, Helvetica, sans-serif;
                          font-size: 19px;
                        }
                        "))
        ),
    
      verbatimTextOutput("renderprint"),
    
      verbatimTextOutput("rendertext"),
      textOutput("rendertext1")
    )
    
    server <- function(input, output, session) {
      output$renderprint <- renderPrint({
        print("This is a render Print output")
      })  
      output$rendertext <- renderText({
        "This is a render Text output - with verbatimTextOutput"
      })
      output$rendertext1 <- renderText({
        "This is a render Text output - with textOutput"
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢,这真的很有用!
    • 我编辑了我的答案并包含了一些 CSS 样式的示例。
    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 2019-05-21
    • 2019-05-01
    • 2017-07-20
    • 1970-01-01
    • 2022-01-10
    • 2019-06-08
    相关资源
    最近更新 更多