Error "argument is of length zero"

4,101 views
Skip to first unread message

Iasmim Louriene

unread,
Sep 29, 2016, 7:49:44 PM9/29/16
to Shiny - Web Framework for R
Hey guys, I'm trying to run an App that makes the download of a plot in png or pdf file, but I once I click in the download button, it redirects me to a window with the following message
"argument is of length zero". Also, in the R console, I got the following:

Listening on http://127.0.0.1:3454
Error in if (input$var3 == "png") png(file) else pdf(file) :
argument is of length zero
Warning: Error in if: argument is of length zero
Stack trace (innermost first):
49: download$func [D:\Documents\Documents\Monografia\Tentativa_II_app_LiDAR\R_Shiny_Tutorial\Scripts\Tutorial 10/server.R#33]
1: runApp
Error in if (input$var3 == "png") png(file) else pdf(file) :
argument is of length zero
Warning: Error in if: argument is of length zero
Stack trace (innermost first):
49: download$func [D:\Documents\Documents\Monografia\Tentativa_II_app_LiDAR\R_Shiny_Tutorial\Scripts\Tutorial 10/server.R#33]
1: runApp

My script for server is this one:

library(shiny)
shinyServer(function(input,output)({

x <- reactive({
iris[,as.numeric(input$var1)]
})

y <- reactive({
iris[,as.numeric(input$var2)]
})


output$plot <- renderPlot({
plot(x(),y())
})

output$down <- downloadHandler(
#Specify the file name
filename = function(){
#iris.png
#iris.pdf
paste("iris", input$var3, sep=".")
},
content = function(file){
# open the device
#create the plot
#close the device
#png()
#pdf()

if(input$var3 == "png")
png(file)
else
pdf(file)
plot(x(),y())
dev.off()
}
)

}))

Does anyone have a clue about what could be done to solve this? Thanks a lot! :)

Winston Chang

unread,
Sep 30, 2016, 1:24:55 PM9/30/16
to Iasmim Louriene, Shiny - Web Framework for R
The problem is probably that input$var3 is NULL or a zero-length vector. You can try print(input$var3) just above the line in question to see what the value is.


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/4a02c2e5-6fb9-4224-a8ef-2b7b784897ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Cheng

unread,
Sep 30, 2016, 3:02:00 PM9/30/16
to Winston Chang, Iasmim Louriene, Shiny - Web Framework for R
And use req(input$var3), probably. http://shiny.rstudio.com/articles/req.html

To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/CANTAc-5vb0F8-vYFdX8GsnMFLNK09hOY0vJdF2Tbd%3D99K6qjUg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages