I am trying to create multiple plots in the same shiny window. Not sure what I am doing wrong. It throws an error that something is up with my main panel.
I tried a few different things but nothing seems to work. Btw this is an adaptation of Mike's answer to this question How can put multiple plots side-by-side in shiny r?
library(ggplot2)
library(gridExtra)
library(shiny)
ui <- fluidPage(
titlePanel("title panel"),
sidebarLayout(position = "left",
sidebarPanel("sidebar panel",
checkboxInput("donum1", "plot1", value = T),
checkboxInput("donum2", "plot2", value = F),
checkboxInput("donum3", "plot3", value = F)
),
mainPanel("main panel", outputplot="myPlot")))
server <- function(input, output, session) {
Feature_A <- c(1, 2,1, 4,2)
Feature_B <- c(4,5,6,6,6)
Feature_C <- c(22,4,3,1,5)
df<- data.frame(Feature_A ,Feature_B ,Feature_C)
pt1 <- reactive({
if (!input$donum1) return(NULL)
p1<-ggplot(data=df, aes(Feature_A))+ geom_histogram()
})
pt2 <- reactive({
if (!input$donum2) return(NULL)
p2<-ggplot(data=df, aes(Feature_B))+ geom_histogram()
})
pt3 <- reactive({
if (!input$donum3) return(NULL)
p3<-ggplot(data=df, aes(Feature_C))+ geom_histogram()
})
output$myPlot = renderPlot({
grid.arrange(p1, p2, p3, ncol=2,top="Main Title")
})
}
shinyApp(ui, server)
EDIT:
Thanks to YBS's comment below, I have been able to figure out the above issue and have made the change to my code above. But the code is not generating any plot. Can someone help please!