2017-02-28 10 views
0

R Shiny에서 사용자가 아래 샘플 코드와 같이 invalidateLater() 값을 제공 할 수있게하려고합니다. 하지만 그것은 "경고 : data.frame : Error : Error : 행의 수가 다른 것을 의미합니다 : 0, 1"오류를 제공합니다. 아래 코드에서 오류 메시지가 있어도 오류가 발생하지 않습니다. 그러나 실제 코드에서는 오류가 발생합니다. 정말로 오류의 원인은 무엇입니까?invalidateLater uiOutput의 반응 입력을 기반으로 "인자가 다른 행 수를 의미 함 : 0, 1"

참고 : ur.R에 numericInput() 및 actionButton()을 직접 삽입하면 모든 것이 잘됩니다. 그러나 나는 그들이 어떤 조건에 따라 따라서 나는 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 인 이유는 무엇입니까? –

관련 문제