'argument is of length zero' error even when checking for NULL

2,727 views
Skip to first unread message

tcash21

unread,
Aug 21, 2013, 2:53:22 PM8/21/13
to shiny-...@googlegroups.com
I keep getting an 'argument is of length zero' error on startup and when selecting different positions (basically whenever selectInput choices need to update). 

I've included only the relevant code here (playerdf and adf are pre-loaded data.frames). I'm not sure how else to check for the inputs being null other than 
  if(is.null(input$player1) | is.null(input$player2)){
                return(invisible())
        }

I still get the error though even when checking for the nulls. The error is occurring in output$text below:


ui.R:
htmlOutput("text")

server.R:
shinyServer(function(input, output){
        input1Choices <- reactive({
                if(!("All" %in% input$position)) {
                        a <- playerdf[playerdf$pos %in% input$position,]$name
                        return(a)
                } else{
                        return(playerdf$name)
                }
        })

input2Choices <- reactive({
              if(!("All" %in% input$position)) {
                p <- playerdf[-grep(input$player1, playerdf$name),]
                p <- p[p$pos %in% input$position,]
                return(p$name)
                } else {
                        return (playerdf[-grep(input$player1, playerdf$name),]$name)
                }
        })

output$player1 <- renderUI({
                selectInput("player1", "", choices=input1Choices())
        })

output$player2 <- renderUI({
                if(is.null(input$player1))
                        return()
                selectInput("player2", "OR", choices=input2Choices())
        })

output$text <- renderPrint({
        if(is.null(input$player1) | is.null(input$player2)){
                return(invisible())
        }
        x1 <- adf[which(adf$pick1 == input$player1 & adf$pick2 == input$player2),]$betterpick
        x2 <- adf[which(adf$pick1 == input$player2 & adf$pick2 == input$player1),]$betterpick
        tp1 <- playerdf[which(playerdf$name == input$player1),]$timesPicked
        tp2 <- playerdf[which(playerdf$name == input$player2),]$timesPicked
        if(tp1 >= tp2){
                tpmin <- tp2
                tpmax <- tp1
        } else if (tp2 >= tp1){
                tpmin <- tp1
                tpmax <- tp2
        }

if(x1 >= x2){
                y <- paste(input$player1, " was drafted <br>", signif((x1 / tpmin) * 100, 3), "% of the time before ", input$player2, sep="")
                o <- HTML(paste("<p><strong>", y, "</p>", sep=""))
                cat(as.character(o))
        } else {
                y <- paste(input$player1, " was drafted <br>", signif((x1 / tpmax) * 100, 3), "% of the time before ", input$player2, sep="")
                o <- HTML(paste("<p><strong>", y, "</p>"))
                cat(as.character(o))
        }


        })
})

Zhuo Jia Dai

unread,
Aug 22, 2013, 12:23:22 AM8/22/13
to shiny-...@googlegroups.com
There's both output$player1 and input$player1 in your code. Better include your ui.R so we can see

Zhuo Jia Dai

unread,
Aug 22, 2013, 1:03:58 AM8/22/13
to shiny-...@googlegroups.com


On Thursday, August 22, 2013 2:53:22 AM UTC+8, tcash21 wrote:

Winston Chang

unread,
Aug 22, 2013, 1:17:18 AM8/22/13
to shiny-...@googlegroups.com
On Wed, Aug 21, 2013 at 11:23 PM, Zhuo Jia Dai <zhuoj...@gmail.com> wrote:
There's both output$player1 and input$player1 in your code. 

That shouldn't cause any problems (although it could be confusing).

-Winston 

tcash21

unread,
Aug 22, 2013, 11:39:53 PM8/22/13
to shiny-...@googlegroups.com
My problem is a bit different in that it does not freeze up the Shiny interface at all, I just see a quick error pop up where the output$text is on the sidePanel saying ''argument is of length zero' but as soon as the reactive input updates, it disappears.

DZJ

unread,
Aug 23, 2013, 2:01:08 AM8/23/13
to shiny-...@googlegroups.com
Do u need to check for if input$position is null?

tcash21

unread,
Aug 23, 2013, 2:14:39 PM8/23/13
to shiny-...@googlegroups.com
Oddly enough, adding a check for is.null(output$player1) seemed to work. However, I see this error in the console:
Error in `$.shinyoutput`(output, player1) : 
  Reading objects from shinyoutput object not allowed.

tcash21

unread,
Aug 23, 2013, 2:17:47 PM8/23/13
to shiny-...@googlegroups.com
Checking for input$position being NULL also worked, so I scrapped the is.null() check on output$player1.
Reply all
Reply to author
Forward
0 new messages