ShinyApp 中的 renderPrint 选项

Gun*_*oen 2 r shiny shiny-server shinyapps

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

有没有办法摆脱它?

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

SeG*_*eGa 5

您可以使用renderText代替renderPrint. 或者也许withMathJax()也是一种选择?

要为您的应用程序设计样式,有几种方法可以做到这一点。你可以在这里阅读。在以下示例中,我将 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)
Run Code Online (Sandbox Code Playgroud)