我分别使用dygraphs和rCharts库在闪亮的应用程序中创建了两个不同的图。由于它们是在两个不同的函数renderChart2和renderDegraph中创建的,我无法使用par(mfrow = c(2,1))来组合我希望将这两个图表结合起来,在我的应用程序中有效地分配空间。
server.R code
output$plot1 <- renderDygraph({
data <- data()
posStart <- as.Date(input$startDate,format="%Y-%m-%d")
posEnd <- as.Date(input$endDate,format="%Y-%m-%d")
if (input$startDate >= input$endDate)
stop("EndingDate must be > StartingDate")
if (input$startDate < input$endDate){
newdata <- data[paste(posStart,posEnd,sep="::"),]
dygraph(newdata)
}
})
output$chart2 <- renderChart2({
data <- data()
posStart <- as.Date(input$startDate,format="%Y-%m-%d")
posEnd <- as.Date(input$endDate,format="%Y-%m-%d")
newdata <- data[paste(posStart,posEnd,sep="::"),]
# barChart(newdata)
# data <- read.csv("C:\\app1\\AAPL.CSV",sep=",")
data.df <- data.frame(cbind(format(index(newdata),"%Y-%m-%d"),coredata(newdata)))
colnames(data.df)[1]<-"date"
data.melt <- melt(data.df)
# newdatamelt <- data.melt[paste(posStart,posEnd,sep="::"),]
print(head(data.df))
print(head(data.melt))
d7 <- dPlot(
x = "date",
y = "AAPL.Volume",
data = data.melt,
type = "bar"
)
d7$addParams(height = 70,width="100%", dom = 'chart2')
return(d7)
})
由于