0
votes

So the problem is that I am using xray package called to plot distributions from my data into Shiny dashboard.

Here is an example of the distributions function usage with my data:

ui <- fluidPage(
     plotOutput("Distribute")
)
server <- function(input, output, session) {

      #For Distribution
      distribute <- reactive({
            distrLongley=longley
            distrLongley$testCategorical=c(rep('One',7), rep('Two', 9))
            xray::distributions(distrLongley, charts = T)
      })
      output$Distribute <- renderPlot({
            #distribute()
            xray::distributions(longley, charts = T)
      })

}

shinyApp(ui, server)

It shows from 3 to 4 distributions but actually it should show more distributions. When running in the console mode, I can see all the plots in plots screen. But when I run it in Shiny, it only shows few charts, which is not the desired output.

I don't know why the function shows all the plots when executing from the RStudio console, but not when executing in Shiny. Unlike in the RStudio plot viewer, there is not an option to move to next page option in Shiny.

1

1 Answers

0
votes

The problem is that longley dataset contains 7 columns and xray package creates two 2 x 2 grids of graphs. And on the first graph it shows 4 graph and the second one it shows 3 graphs. The last graph overdraw the first one.

To cope with the problem you can temporarily save two graphs into two PNG file then load them into imageOutput. Please see the code below:

library(xray)
library(shiny)

ui <- fluidPage(
  imageOutput("Distribute1"),
  imageOutput("Distribute2")
)

server <- function(input, output, session) {
  png("x%03d.png")
  xray::distributions(longley, charts = T)
  dev.off()


  output$Distribute1 <- renderImage({
    list(src = "x001.png")
  }, deleteFile = FALSE)
  output$Distribute2 <- renderImage({
    list(src = "x002.png")
  }, deleteFile = FALSE)
}

shinyApp(ui, server)

Output:

pict