I am trying to plot multiple plots on different pages in my shiny app. Here is a reproducible example:
My module code is :
library(ggplot2)
dfunc <- function(data, page_number) { p <- ggplot(data = data, aes(x = data[, 3], y = data[, 2])) +
geom_point() for (i in 1:page_number) {
print(p) } }
dfUI <- function(id) { ns <- NS(id)
tagList(titlePanel("Multi plots"),
sidebarLayout(
sidebarPanel(
numericInput(
ns("page_number"),
"Number of Plots",
1,
min = 1,
step = 1
),
actionButton(ns("generateplot"), "Generate Plot")
),
mainPanel(plotOutput(ns("view")))
)) }
df <- function(input, output, session) { observeEvent(input$generateplot, {
output$view <- renderPlot({
data = mtcars
dfunc(data = data,
page_number = input$page_number)
}) }) }
There is a global file which calls this file where these functions are stored: through this:
library(shiny)
library(shinythemes)
source("modules/dfunc.R")
The server file is like this :
source('global.R')
shinyServer(function(input, output, session) {
callModule(df, "dfunc")
})
And ui.R is like this :
source('global.R')
shinyUI(fluidPage(
shinythemes::themeSelector(),
headerPanel("The Shiny App"),
tabsetPanel(
tabPanel("Multi page plot", dfUI('dfunc')),
type = "pills"
)
))
Now the issue is if I use my dfunc function it prints as many plots as I give in page_number but when I call similar function in shiny app it only prints the single one. Is there any way that shiny app can print as many plots required on same page or on multiple page.
Thanks in advance.