server.R
의
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 부분
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 기능은 자주 발생 함수는 server.R
에 실행될 의미이며 ui.R
에 있습니다.
renderUI
은 본격적인 클라이언트 측 UI를 만들 예정입니다. 즉, 동적 UI에서 반환하는 모든 코드 (실제로는 server.R
에 저장되어야 함)가 ui.R
에 존재할 수있는 유효한 클라이언트 측 코드 여야하며, 이는 테스트가 훨씬 쉬울 수 있음을 의미합니다. 동적으로 만들려는 코드 (예 : out
tabsetPanels 중 하나)를 ui.R
으로 이동하면 나중에 쉽게 디버깅 할 수 있습니다.
이 경우에는 문제가 있다고 생각합니다. 당신은 당신이 그것을했다면 renderPlot
호출 주위에있다 볼 수 있습니다. 그냥 여기에 동적 UI를 만들고있어,이 경우 plotOutput("plotName")
, UI 호환 기능을 사용하려면. 다음 서버 쪽에서 ' 해당 출력에 플롯을 할당합니다.
output$plotName <- renderPlot({
...
})
플롯이 표시 될 때 원하는대로 작동하며 플롯이 표시되지 않을 때 효과가 나타나지 않습니다.