My ggvis plot depends on several input fields that work like filter for input data. For some of combinations the resulting data frame is empty and ggvis throws error and breaks the whole application. I tried to put
if(nrow(inputdataframe) == 0) return NULL
if(nrow(inputdataframe) == 0) return ggvis()
which didn't help. What is the proper return parameter in this situation (I want to have an empty plot or some text message instead)?
server.R
effvis <- reactive ({
dta <- siteeff()
if(nrow(dta) == 0) return(NULL)
dta %>%
ggvis(~param.value, ~yvar) %>%
layer_points( size := 50, size.hover := 200) %>%
set_options(width = 800, height = 500)
})
effvis %>% bind_shiny("effplot")
ui.R --
ggvisOutput("effplot")
Update
I don't want to show all data when data is empty (as suggested here) It's confusing
In my case, with the latest shiny, I can just send an empty data.table (or data.frame) and shiny just plots an empty graph (the data.frame or data.table has to have the corresponding columns)