I have a drop-down menu and I need a plot to be reactive to the choice the person makes. I am having a hard time making it work on my dashboard

时间:2019-04-17 01:59:46

标签: r shiny plotly reactive flexdashboard

I am having a hard time correctly making my chart reactive to the choice made in a drop-down menu.

I have made it work using different data but can not make it work now. I am also looked up about different ideas and was not successful.

Here's the code:

Prediction_with_CusID <- cbind(SepthruNov_flipkart_new_data, predict(model_fit, newdata = SepthruNov_flipkart_new_data, type = 'prob'))

Predictive- Customer Churn Rate

###Probability of Customer Churn by Month

zero_19 <- Prediction_with_CusID %>%
  filter(X1 < "0.00", X1 > "0.19")


twenty_39 <-Prediction_with_CusID %>%
  filter(X1< "0.20" ,  X1 > "0.39")


fourty_59<- Prediction_with_CusID %>%
  filter(X1<= "0.40",  X1>= "0.59")

sixty_79 <-Prediction_with_CusID%>%
  filter(X1< "0.60", X1 > "0.79")

septhruNov_customers <- Prediction_with_CusID %>%
  filter(X1, CustomerID) %>%
  na.omit(Prediction_with_CusID)



septhruNov_customer_sample <- septhruNov_customers$X1

septhruNov_customer_sample_list <- septhruNov_customers$X1

selectInput("septhruNov_customer", "Percentages", 
    c("60-79%"= "sixty_79", 
    "40-59%" = "fourty_59", 
    "20-39%" = "twenty_39", 
    "0-19%" = "zero_19"))


  cust_input <- reactive ({ 
  Prediction_with_CusID$X1 %>%
    filter(X1== input$septhruNov_customer_sample_list)})


renderPlot({ggplot(cust_input(), aes(x = average_gap, y = X1)) +
  geom_point(shape = 1, colour = "#51A0D5") + 
  labs( x = "Customer ID", 
        y = "Churn Rate", 
        title = "Churn Probability")+
  geom_hline(yintercept=0.5, linetype="dashed", color = "#2C528C", size=0.5) +
  theme_classic()
})

1 个答案:

答案 0 :(得分:0)

我没有任何数据可以测试,但我认为可能是以下问题。

  cust_input <- reactive ({ 
  Prediction_with_CusID$X1 %>%
    filter(X1== input$septhruNov_customer_sample_list)})

(我假设管道运算符和“过滤器”功能为dplyr) 您在使用过滤器之前先参考字段$X1。 请尝试以下操作:

  cust_input <- reactive ({ 
  Prediction_with_CusID %>%
    filter(X1== input$septhruNov_customer_sample_list)})

发生了什么事,一个向量被传递给了需要一个数据帧的过滤器函数。