0

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()
})

Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27
  • Can you show me the error code? – Sang won kim Apr 17 '19 at 02:34
  • it shows the drop down and no chart. It says "Error: no applicable method for "filter_' applied to an object of class "c('double, numeric')" – Elizabeth Snowden Apr 17 '19 at 02:45
  • As I know, It's data cleansing problem. I didn't look over your data, I'm not sure. I guess it happened on the eighth code(selectInput function), please check your environment of filter. – Sang won kim Apr 17 '19 at 03:12
  • Welcome to S.O. Please read the [question guidelines](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and edit your question. – shea Apr 17 '19 at 04:25

1 Answers1

0

I do not have any data to test with, but I think the following might be the problem.

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

(I assume the pipe operator and "filter" function are dplyr) You refer to a field $X1 before using filter. Please try the following:

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

What happened was that a vector was passed to the filter function, which expects a dataframe.

Siete
  • 328
  • 3
  • 14
  • Hi @Elizabeth Snowden, did some of this answer your question? if so, could you accept my answer of provide your own solution? Thanks in advance. – Siete May 03 '19 at 10:52