基于uiOutput的无功输入的InvalidateRater在Shining中导致;参数表示不同的行数:0,1“;

基于uiOutput的无功输入的InvalidateRater在Shining中导致;参数表示不同的行数:0,1“;,r,shiny,R,Shiny,在R中,我希望允许用户提供invalidateLater()的值,如下面的示例代码中所示,但它给出了“警告:data.frame中的错误:参数意味着不同的行数:0,1”。在下面的代码中,即使有错误消息,也不会失败。然而,在我的实际代码中,它会导致失败。到底是什么导致了错误 注意:如果我直接将numeriInput()和actionButton()放在ur.R中,一切都会顺利进行。但是,我希望它们基于某些条件显示,因此我希望使用renderUI()和uiOutput() ui.R library(

在R中,我希望允许用户提供invalidateLater()的值,如下面的示例代码中所示,但它给出了“警告:data.frame中的错误:参数意味着不同的行数:0,1”。在下面的代码中,即使有错误消息,也不会失败。然而,在我的实际代码中,它会导致失败。到底是什么导致了错误

注意:如果我直接将numeriInput()和actionButton()放在ur.R中,一切都会顺利进行。但是,我希望它们基于某些条件显示,因此我希望使用renderUI()和uiOutput()

ui.R

library(shiny)

shinyUI(fluidPage(

    checkboxInput('refresh',em("Refresh"),FALSE),
    uiOutput("interval_update"),
    uiOutput("go_refresh"),
    plotOutput("plot")

 ))
 library(shiny)

 shinyServer(function(input, output) {

    output$interval_update=renderUI({
            if(input$refresh==TRUE){
                    numericInput("alert_interval", em("Alert Interval   (seconds):"),5 ,width="200px")
            }
    })

    output$go_refresh=renderUI({
            if(input$refresh==TRUE){
                    actionButton("goButton", em("Update"))
            }
    })

    alert_interval = reactive({
            input$goButton
            z=isolate(input$alert_interval)
            z=z*1000
            z
    })


    output$plot <- renderPlot({
            if(input$refresh==TRUE){
                    invalidateLater(alert_interval())
                    hist(rnorm(1000))
            }
    })
  })
server.R

library(shiny)

shinyUI(fluidPage(

    checkboxInput('refresh',em("Refresh"),FALSE),
    uiOutput("interval_update"),
    uiOutput("go_refresh"),
    plotOutput("plot")

 ))
 library(shiny)

 shinyServer(function(input, output) {

    output$interval_update=renderUI({
            if(input$refresh==TRUE){
                    numericInput("alert_interval", em("Alert Interval   (seconds):"),5 ,width="200px")
            }
    })

    output$go_refresh=renderUI({
            if(input$refresh==TRUE){
                    actionButton("goButton", em("Update"))
            }
    })

    alert_interval = reactive({
            input$goButton
            z=isolate(input$alert_interval)
            z=z*1000
            z
    })


    output$plot <- renderPlot({
            if(input$refresh==TRUE){
                    invalidateLater(alert_interval())
                    hist(rnorm(1000))
            }
    })
  })
库(闪亮)
shinyServer(功能(输入、输出){
输出$interval\u update=renderUI({
如果(输入$refresh==TRUE){
数字输入(“警报间隔”,em(“警报间隔(秒):”),5,width=“200px”)
}
})
输出$go\u刷新=renderUI({
如果(输入$refresh==TRUE){
actionButton(“goButton”,em(“Update”))
}
})
警报间隔=无功({
输入$goButton
z=隔离(输入$alert\u间隔)
z=z*1000
Z
})

输出$plot
输入$alert\u interval
在您第一次调用它时为
NULL
。因此,
alert\u interval()
将是一个
数值(0)
,这将导致
renderPlot()中出现错误

您可以通过检查其长度来测试
alert\u interval()
是否“就绪”:

 output$plot <- renderPlot({
    if(input$refresh==TRUE & length(alert_interval())){
      ...    
    }
  })

output$plot非常感谢!在numeriInput(“警报间隔”,em(“警报间隔(秒):”),5,width=“200px”)中,我提供了5秒作为默认值。为什么我第一次调用它时它是空的?