【发布时间】:2018-11-24 04:47:38
【问题描述】:
我创建了一个闪亮的应用程序,需要一些关于我的数据子集的帮助。我插入了一个dateRangeInput,客户端可以在其中过滤开始日期和结束日期。将该过滤器包含在我的GGPOT代码中,以便在选择不同的日期时,绘图始终会自动更改。我的问题是它没有根据所选日期进行过滤,partC 的数据。问题是这行代码:geom_line(aes(x = Date, y = OLS.Data[partC]), color="red")。 partC 是一个连接到选择输入以访问我的数据框的变量。示例:客户端选择input1 = Informed 和input2 = Full,partC 使InformedFull(这是我的数据集的一列的名称)等等。所以partC 只是两个输入的连接器,这是我的问题。如果我将这段代码(例如geom_line(aes(x = Date, y = InformedFull), color="red"))放入我的 geom_line,则上面的一切都可以完美运行,但我需要它与 partC。
这是我的 ui.R 代码(仅必要部分):
box(
title = "Controls-0",
status = "primary",
solidHeader = TRUE,
width = 3,
height = 142,
dateRangeInput("daterange", "SELECT DATE:", start = min(OLS.Data$Date), end = max(OLS.Data$Date))
),
box(
title = "Investor Control",
status = "primary",
solidHeader = TRUE,
width = 3,
selectInput("investor", label="Select Investor", choices = list("Informed" = "Informed", "Noise" = "Noise"), selected = "Informed")
),
box(
title = "Category Control",
status = "primary",
solidHeader = TRUE,
width = 3,
selectInput("category", label="Select Category", choices = list("Full" = "Full", "Fact" = "Fact", "Fact Positive" = "Fact.Pos", "Fact Negative" = "Fact.Neg", "Emotions" = "Emotions", "Emotions Fact" = "EmotionsFact"), selected = "Full")
),
用 ggplot 更新 server.R:
server <- function(input, output) {
partC = NULL
makeReactiveBinding("partC")
observeEvent(input$investor, {
partA<<-input$investor
partA<<-as.character(partA)
})
observeEvent(input$category, {
partB<<-input$category
partB<<-as.character(partB)
})
OLS.Data$InformedEmotionsFact <- as.numeric(as.character(OLS.Data$InformedEmotionsFact))
OLS.Data$NoiseEmotionsFact <- as.numeric(as.character(OLS.Data$NoiseEmotionsFact))
output$myPlotVisu <- renderPlot({
partC<-as.character(paste(partA,partB,sep=""))
OLS.Data %>%
select(partC, NYSE,Date,Sector) %>%
filter(Date >= input$daterange[1], Date <= input$daterange[2]) %>%
ggplot(aes(x = Date, y = NYSE)) +
geom_line() +
ggtitle(paste(input$investor,input$category,sep = "")) +
theme(plot.title = element_text(hjust = 0.5,face="bold")) +
labs(x="Time",y="Return S&P500") +
geom_line(aes(x = Date, y = OLS.Data[partC]), color="red")
})
【问题讨论】: