【问题标题】:render graphics after inputting information in Shiny在 Shiny 中输入信息后渲染图形
【发布时间】:2021-05-18 21:57:30
【问题描述】:

我正在尝试在输入某些参数后生成一些图表,但是,在输入某些图表时它们会抛出错误,因为尚未输入输入,所以如果值为 null,我就想到了,不要制作图表但附件代码不起作用:

shinyApp(ui =
           fluidPage(sidebarPanel(numericInput('x','x', value = NULL),
                                  numericInput('x2','x2', value = NULL),
                                  numericInput('x3','x3', value = NULL)), 
                     mainPanel(renderPlot('plot1'))),
         
         server = function(input, output, session){
           
         condition <- reactive(is.null(input$x) | is.null(input$x2) |is.null(input$x3))
         
         output$plot1 <- renderPlot(if(condition()){NULL}else{plot(1:10,1:10)})
         
         })

我会很感激有办法做到这一点,谢谢。

【问题讨论】:

  • 可能使用req function 获取所需参数。您的示例似乎没有产生任何错误,因此很难用于测试可能的解决方案。代码“不工作”究竟如何?
  • 谢谢,效果很好!!

标签: r shiny shinydashboard shiny-server


【解决方案1】:

您的ui 代码中有一个错误,根本无法显示任何绘图,您应该替换:

mainPanel(renderPlot('plot1'))

与:

mainPanel(plotOutput('plot1'))

正如@MrFlick 评论中所述,您可以使用req() 进行必要的输入:

output$plot1 <- renderPlot(
  {
    req(input$x, input$x2, input$x3)
    plot(1:10,1:10)
  })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-28
    • 2011-05-30
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 2021-11-04
    相关资源
    最近更新 更多