Mümin
Mümin

Reputation: 309

Filter results in ShinyApp

i have a shiny app Item Correlation which get the correlation between several products. and i want to get only the values which's more than zero without removing the sorted results. and this's my server code:

server <- function(input,output){
  data<- reactive({
    input$Item
  })
  output$Itemcorr <- renderTable({
    DF %>% filter(FirstItem == data())  %>% arrange(desc(X.Correlation))
  })

  output$plot <- renderPlot({
    barplot(subset(DF$X.Correlation, DF$FirstItem == data()),main="X.Correlation Distribution", 
            xlab="SecondItems",ylab="Percent",xlim=c(1,60),ylim = c(0,100), col=c("darkblue","red"),names.arg =subset(DF$SecondItem, DF$FirstItem == data())
    )
  })

Upvotes: 1

Views: 97

Answers (1)

akrun
akrun

Reputation: 886948

We can do a couple of things here,

1) create the second condition also in the same filter

2) In the reactive call we do the data subsetting

server <- function(input,output){

 data<- reactive({
    DF %>% 
       filter(FirstItem == input$Item, X.Correlation > 0) %>% 
       arrange(desc(X.Correlation))
    })

 output$Itemcorr <- renderTable({
    data()
  })

 output$plot <- renderPlot({
    barplot(data()$X.Correlation),main="X.Correlation Distribution", 
            xlab="SecondItems",ylab="Percent",xlim=c(1,60),ylim = c(0,100),
    col=c("darkblue","red"),names.arg =data()$SecondItem)
    )
  })

Upvotes: 1

Related Questions