I'm pretty new at this so forgive me - I'm building an app in Shiny that takes an uploaded data file of a fixed format, and renders out various plots based on user selections. One important part of the app is a set of tabs which each contain one plot.
I'm using renderUI to render the tabs but I'm having a bunch of difficulty rendering the plot. I've tried renderPlot, outputPlot and can't get the plot to show. I get various errors but the code below is generating "Error in as.character(x) : cannot coerce type 'closure' to vector of type 'character'" at the point where we renderPlot(engPlot).
ui.R
# Define UI
shinyUI(fluidPage(
# Application title
titlePanel("Chart Creation Tool"),
# Sidebar
sidebarLayout(
sidebarPanel(
fileInput("fileBlob", "Upload File", multiple = FALSE, accept = NULL),
selectInput("selectAnalysis", label=h3("Select Input"), choices=c("Month x Year", "Strategies", "Programs", "Segments")),
uiOutput("strategyList")
),
# Show a plot of the generated distribution
mainPanel(
uiOutput("mainPanel")
)
)
))
mainPanel portion of server.R
output$mainPanel <- renderUI ({
if (length(RawImport())==0L) {
out <- NULL
}else{
if (input$selectAnalysis=="Month x Year") {
dfAggMonth <- aggregate(cbind(Sent,Delivered,UniqueOpens,Responders,Bounced,Unsubscribes,TotalSpamComplaints,HardBounces,SoftBounces) ~ SentMonth + SentYear + SentMonthName, RawImport(), FUN = sum)
dfAggMonth <- addRatios(dfAggMonth)
dfAggMonth <- dfAggMonth[with(dfAggMonth, order(Date)), ]
engPlot <- runplot(paste(dfAggMonth$SentMonthName, dfAggMonth$SentYear,sep="-"), dfAggMonth$Date, dfAggMonth$Delivered, dfAggMonth$UniqueOpenRate, dfAggMonth$ResponderRate, "engagement", , "Temp Title")
out <- tabsetPanel(
tabPanel("Engagement", "Engagement", renderPlot(engPlot)),
tabPanel("Summary", "summary", "summary"),
tabPanel("Deliverability",runplot(paste(dfAggMonth$SentMonthName, dfAggMonth$SentYear,sep="-"), dfAggMonth$Date, dfAggMonth$Delivered, dfAggMonth$BounceRate, , "deliverability", , "Temp Title"))
)
}
else {
out <- tabsetPanel(
tabPanel("Tab 1", input$selectAnalysis),
tabPanel("Tab 2", input$selectAnalysis)
)
}
}
out
})
RunPlot Function
runplot <- function(xSeriesLabels, xSeriesValues, leftseries, rightseries1, rightseries2, chartType, columnSeries, xTitle){
if (missing(xTitle)==FALSE) {
strTitle <- xTitle
} else {
strTitle <- "no title supplied"
}
p <- barplot(leftseries, width=1, col=barCol, axisnames = leftseries, names.arg=xSeriesLabels, axis.lty=1, xlab=strTitle)
return(p)
}