Problem whith reactive filter in my plot

Hi!
I've a problem with my shiny.

I've a plot that changes when you select "State" and "Segment".

output$fig11 <- renderPlot({
      pais_re() %>% 
        ggplot(aes(x=Semestre))+
        geom_col(aes(y=Total), fill="#80b1d3")+
        geom_col(aes(y=Ganancia), fill="#fdb462")+
        geom_hline(aes(yintercept=median(Supertienda_rfm$Ganancia)), color="#fc4e2a")+
        geom_hline(aes(yintercept=median(Supertienda_rfm$Total)), color="#023858")+
        facet_grid(~Value)+
        ggthemes::theme_solarized()+
        labs(title = "Ventas y ganancias totales por",
             subtitle = "segmentación de clientes y provincia",
             x="",
             y="$",
             caption = "Ventas (celeste). Ganancias(naranja) ")+
        theme(plot.background = element_rect(size = 1, color = 1),
              plot.title = element_text(size = rel(0.9), face = "bold"),
              plot.subtitle = element_text(size = rel(0.9), face = "bold"),
              plot.caption = element_text(hjust = 0.2),
              axis.text.x = element_text(size = rel(0.8), angle = 90),
              axis.text.y = element_text(size = rel(0.8)),
              axis.title.x = element_text(size = rel(0.8)),
              axis.title.y = element_text(size = rel(0.8)))
    })

My filters are:

  #Filtro de segmentación por provincia
  segmento <- reactive({
    re3 <- Supertienda_rfm %>% filter(Estado==input$id_prov) %>% 
      select(segment) %>% 
      unique() %>% 
      pull()
    
    re3
  })
  
  output$id_seg <- renderUI({
    selectInput(inputId = "id_seg",
                label = "Segmento:",
                choices = segmento())
  })
  
  #Reactive box por país y segmento
  pais_re <- reactive({
    re2 <- Supertienda_rfm %>% filter(Estado==input$id_prov & segment==input$id_seg  )
    re2
  })

When I run the app, it shows me a warning message everytime I change the filters:

Warning: Error in : Problem with filter() input ..1.
i Input ..1 is Estado == input$id_prov & segment == input$id_seg.
x Input ..1 must be of size 10254 or 1, not size 0.
138:

How I can fix it?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.