私はこれにかなり慣れていないので、ご容赦ください。アップロードされた固定形式のデータ ファイルを取得し、ユーザーの選択に基づいてさまざまなプロットをレンダリングするアプリを Shiny で構築しています。アプリの重要な部分の 1 つは、それぞれ 1 つのプロットを含む一連のタブです。
タブをレンダリングするためにrenderUIを使用していますが、プロットをレンダリングするのが非常に困難です。renderPlot、outputPlot を試しましたが、プロットを表示できません。さまざまなエラーが発生しますが、以下のコードは、renderPlot(engPlot) の時点で「as.character(x) のエラー: 型 'closure' を型 'character' のベクトルに強制することはできません」を生成しています。
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")
)
)
))
server.R の mainPanel 部分
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 関数
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)
}