【发布时间】:2019-03-20 14:53:15
【问题描述】:
我有数据集,我已经转换成以下格式并根据它绘制图表。
structure(list(Date = structure(c(17833, 17830, 17829, 17828,
NA), class = "Date"), stocks = structure(c(1L, 1L, 1L, 1L, 1L
), .Label = c("DBS SP Equity", "OCBC SP Equity", "ST SP Equity"
), class = "factor"), cumulative = c(22.99, 23.1, 23.71, 24.1,
NA), Industry = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("Banks",
"Telecommunications"), class = "factor")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame"))
我有 2 个输入字段:Industry 和 DateRange。
我的意见
selectInput(inputId = "industry2",
label = "Industry",
choices = input_selection[input_selection !='MarketIndex'],
selected = NULL,
multiple = TRUE),
dateRangeInput('dateRange',
label = 'Date range input: yyyy-mm-dd',
start = min(sharesdata_gather$Date), end = max(sharesdata_gather$Date))
我能够为我的原始数据结构中的所有数据绘制 2 个图表 - 行业与日期和库存与日期。
但不能仅针对用户指定的日期绘制图表。我尝试使用子集函数来过滤图形,但得到错误“没有活动的反应上下文不允许操作。(你试图做一些只能从反应表达式或观察者内部完成的事情。)”
我的服务器功能是:
#filtering the data for input start and end date
dailyprice_gather <- subset(dailyprice_gather, Date>=input$dateRange[1] )
dailyprice_gather <- subset(dailyprice_gather, Date<=input$dateRange[2] )
#grap for Date vs Cumulative for each industry
output$ind=renderPlot({
ggplot(data = dailyprice_gather[dailyprice_gather$Industry == input$industry2,]) +
geom_line(aes(x= Date , y= cumulative, color=Industry) , size=0.25) +
ggtitle(paste0("Simple Cumulative Return over Years - Industry Wise"))
})
#graph for Date vs Stock
output$stk =renderPlot({
ggplot(data = dailyprice_gather[dailyprice_gather$Industry == input$industry2 & dailyprice_gather$stocks == input$equities,])+
geom_line(aes(x= Date , y= cumulative, color=stocks) , size=0.25) +
ggtitle(paste0("Simple Cumulative Return over Years - Stock Wise"))
})
【问题讨论】: