2017-02-28 11 views
0

R Shinyでは、以下のサンプルコードのようにinvalidateLater()の値をユーザーに提供しますそれは "警告:data.frame:errorsのエラー:行数が異なることを暗示しています:0,1"となります。以下のコードでは、エラーメッセージがあっても失敗しません。しかし、実際のコードでは、エラーが発生します。本当にエラーの原因は何ですか?invalidateLater uiOutputからの反応入力に基づいて、 "引数は行数が異なることを暗示しています。"

注:私が直接numericInput()とactionButton()をur.Rに配置すると、すべてうまく行きます。しかし、私は彼らが、いくつかの条件に基づいて、したがって、私はrenderUI()とuiOutput()

ui.R

library(shiny) 

shinyUI(fluidPage(

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

)) 

server.R

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)) 
      } 
    }) 
    }) 
使用したい見せたいです

答えて

1

input$alert_intervalは、初めて電話を受けるときにはNULLです。したがって、alert_interval()numeric(0)となり、これによりrenderPlot()にエラーが発生します。

alert_interval()は、その長さをチェックすることで、「準備完了」であるかどうかをテストすることができます:

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

はどうもありがとうございました! numericInput( "alert_interval"、em( "アラート間隔(秒):")、5、width = "200px")では、デフォルト値として5秒を指定しました。なぜ私はそれを初めて呼んだときにnullですか? –

関連する問題