0

Hi I'm using both selectize and dropdownbuttons to build multiple choices select widget for my user. It works fine when single choice is made, however when you make multiple choices, the aggregate data showed is incorrect. Here is my code:

ui:

library(shiny)

shinyUI(fluidPage(


      dropdownButton(
        label = "Country", status = "default", width = 400,
        checkboxGroupInput(inputId = "var", label = "Country", 
                           choices = c("ALL", "Null", "A2", "AE", "AF"),
                           selected = c("ALL") )
      ),

      hr(),

      dropdownButton(
        label = "Platform       ", status = "default", width = 400,
        checkboxGroupInput(inputId = "plat", label = "Platform       ", 
                           choices = c("ALL", "Android","Ios"),
                           selected = c("Android"))
      ),

      hr(),
      selectizeInput(inputId ='media',
        label = "Source",
                           choices = c("ALL", "facebook", "twitter"),
        selected = c("ALL"),
        multiple = T),   


    ),
    mainPanel(


      textOutput("text1")
  )
))

server:

#server.R

library(shiny)
library(ggplot2)
library(dplyr)
df <- df

shinyServer(function(input, output, session) {



  datasetInput <- reactive({

   df<- df %>%
      filter(
        (input$var == 'ALL' | country == input$var)&
          (input$plat == 'ALL' | platform == input$plat)&
          (input$media == 'ALL' | media_source == input$media)
      )

  })




  output$text1 <- renderText({paste("Revenue: $", df()  %>%
                                      summarise(revenue = sum(price)/100)})



})

When I make single choice, the data is correct, ex) when I choose facebook for media, the revenue is 200,000, when i choose twitter, the revenue is 50,000. So I want to see 250,000 when I choose both. however, when the number is quite odd when i'm doing so, I got something like 160,000, which is hard to know how does the system calculate it. Same problems with the other two select widget.

BTW, I'm also getting this warning message:

longer object length is not a multiple of shorter object length

Anyone knows which part I did wrong? Thank you.

cat88
  • 209
  • 4
  • 12
  • 1
    You are not actually asking shiny question but dplyr question. Proper question would have been how to filter multiple conditions in dplyr? Check this: http://stackoverflow.com/questions/25647470/filter-multiple-conditions-dplyr – Mikael Jumppanen Apr 20 '16 at 05:01
  • Thank you for your help! You are right! My problem is solved. – cat88 Apr 20 '16 at 17:45

0 Answers0