【问题标题】:R Shiny print HTML text in renderplotR Shiny在渲染图中打印HTML文本
【发布时间】:2020-08-20 02:03:22
【问题描述】:

在应用程序的服务器部分中是否有可能在 renderPlot 函数中具有如下内容:

output$plotting <- renderPlot({
    if (value == 1 ) {
        grid.arrange(plot1, plot2,nrow=1, ncol=2)
    } else {
    # Print a generic message with an h1() or p() function.
    }
})
    

我能够渲染情节,但无法打印通用消息。这可能吗?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    renderPlot 需要一个生成绘图的表达式。因此,您不能将 html 标签传递给它。

    但是,您可以使用conditionalPanel 根据条件显示 UI 元素:

    library(shiny)
    
    ui <- fluidPage(
      checkboxInput("toggle", "toggle"),
      conditionalPanel("input.toggle == true", plotOutput("myPlot")),
      conditionalPanel("input.toggle == false", p("Generic message"))
    )
    
    server <- function(input, output, session) {
      output$myPlot <- renderPlot({plot(1:10)})
    }
    
    shinyApp(ui, server)
    

    另一种方法可以通过使用renderUI来实现:

    library(shiny)
    
    ui <- fluidPage(
      checkboxInput("toggle", "toggle"),
      uiOutput("myUIOutput")
    )
    
    server <- function(input, output, session) {
      
      output$myPlot <- renderPlot({plot(1:10)})
      
      output$myUIOutput <- renderUI({
        if(input$toggle == TRUE){
          plotOutput("myPlot")
        } else {
          p("Generic message")
        }
      })
      
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2020-04-26
      • 1970-01-01
      • 2020-06-19
      • 2021-11-04
      • 2020-11-08
      • 2014-09-12
      • 2021-03-20
      • 1970-01-01
      • 2013-06-21
      相关资源
      最近更新 更多