Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny - Black box appearing when returning NULL to plotOutput

Tags:

r

shiny

In the following very MWE I get a black filled box where the plot should be instead of nothing when I first run the source.

I say nothing because the table does not (IMO correctly) show until the button is clicked. I expect the same behaviour for a plot i.e. until the button is clicked all that will be on screen is the button. What am I doing wrong?

library(shiny)

myUI = bootstrapPage( 
  actionButton(inputId="gobutton", label="Go"),
  plotOutput("plot"),
  tableOutput("table")
  )

mySERVER = function(input, output) {
  output$plot <- renderPlot({ 
    if(input$gobutton==0) {return(NULL)}
    hist(runif(100))
  })
  output$table <- renderTable({ 
    if(input$gobutton==0) {return(NULL)}
    data.frame(x=runif(10), y=seq(1:10))
  })

}

runApp(list(
  ui = myUI,
  server = mySERVER
  ))

I'm using Firefox and the latest stable R & shiny.

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8    
 [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8   
 [7] LC_PAPER=en_GB.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_0.8.0

loaded via a namespace (and not attached):
[1] bitops_1.0-6  Cairo_1.5-5   caTools_1.16  digest_0.6.4  httpuv_1.2.2 
[6] Rcpp_0.11.0   RJSONIO_1.0-3 tools_3.0.2   xtable_1.7-1
like image 769
nstjhp Avatar asked Dec 30 '25 20:12

nstjhp


1 Answers

I think this has to do with the Cairo package.

My system did not have Cairo installed. If I run your code in Firefox with a fresh R session, no black box (just the GO button).

I then install and load Cairo. When I re-run your code, I get the black box.

I then unload Cairo detach("package:Cairo", unload=T) : still get black box.

I then restart R and run your code: still black box.

I then ininstall Cairo remove.packages("Cairo") and restart R: no black box.

So it appears the Shiny will load Cairo if it is intstalled, and that is what causes the black box.

like image 135
jlhoward Avatar answered Jan 01 '26 11:01

jlhoward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!