title: How to use ShinyApp to choose 3 specific factor variables among all for creating plot according to them with "ggplot2" package?
body: <p>I am new to shiny package,I want to create an app for my Data which choose 3 specific variables among 4 variables and create the plot according to them.My data is:</p>
  
  <pre><code>month &lt;- 
  as.factor(c("sep","oct","nov","nov","oct","oct","oct","nov","sep","oct"))
  cost &lt;- as.numeric(sample(1000:10000,10,replace=F))
  Type &lt;- as.factor(c("T1","T1","T3","T1","T2","T3","T1","T3","T2","T2"))
  class &lt;- as.factor(c("R","Q","R","R","R","Q","Q","Q","R","R"))
  sex &lt;- as.factor(c("M","F","F","F","M","F","F","M","M","F"))
  
  f &lt;- data.frame(month , cost , Type , class , sex)
  f
  
  f1 &lt;- as.data.frame(aggregate(f[c("cost")],
                            by=f[c("month","Type","class","sex")],
                            FUN="mean"))
  f1$percent &lt;- f1$cost/sum(f1$cost)
  
  f1
  </code></pre>
  
  <p>As you can see my data has 4 factor variable,I want the user to choose 3 of them and plot according to the 3 chosen variables.It is important that which variable is chosen for x_axis and which is chosen for fill parameter and which one for facet_grid's argument.</p>
  
  <p><strong>what I want to do in an interactive way:</strong></p>
  
  <pre><code>library(ggplot2)
  
  ggplot(f1 , aes(x=month ))+
  geom_bar(stat="identity",aes(y=percent , fill=Type) ,colour="black", 
    position = position_dodge())+
  scale_y_continuous(labels = scales::percent)+
  labs(x="month" , y="cost percentage")+
  facet_grid(sex ~ class)+
  theme(strip.text.x = element_text(size=8),
      strip.text.y = element_text(size=5, face="bold"),
      strip.background = element_rect(colour="red", fill="#CCCCFF"))+
  labs(x="month" , y="percentage" )
  </code></pre>
  
  <p><strong>What I have tried:</strong></p>
  
  <pre><code>library(shiny)
  library(ggplot2)
  ui &lt;- fluidPage(
  
  titlePanel("Report"),
  sidebarLayout(
  sidebarPanel(
  
    selectInput("variable1", "Variable1:",
                choices = c("month","Type","class","sex")),
  
    selectInput("variable2", "Variable2:",
                choices = c("month","Type","class","sex")),
  
    selectInput("variable3", "Variable3:",
                choices = c("month","Type","class","sex")),
  
    ),
  
    mainPanel(
    plotOutput("disPlot")
  
        )
       )
      )
  
   server &lt;- function(input, output) {
   var1 &lt;- reactive({
   switch (input$variable1,
          "month"=month,
          "Type"=Type,
          "class"=class,
          "sex"=sex
     )
    })
  
   var2 &lt;- reactive({
   switch (input$variable2,
          "month"=month,
          "Type"=Type,
          "class"=class,
          "sex"=sex
      )
    })
  
   var3 &lt;- reactive({
   switch (input$variable3,
          "month"=month,
          "Type"=Type,
          "class"=class,
          "sex"=sex
     )
    })
  
  
   output$disPlot &lt;- renderPlot({
   variable1 &lt;- var1()
   variable2 &lt;- var2()
   variable3 &lt;- var3()
     ggplot(f1 , aes(x=variable1 ))+
      geom_bar(stat="identity",aes(y=percent , fill=variable2) 
      ,colour="black", position = position_dodge())+
      scale_y_continuous(labels = scales::percent)+
      labs(x="variable1" , y="cost percentage")+
      facet_grid(. ~ variable3)+
      theme(strip.text.x = element_text(size=8),
          strip.text.y = element_text(size=5, face="bold"),
          strip.background = element_rect(colour="red", fill="#CCCCFF"))+
      labs(x="variable1" , y="percentage" )
  
  
        })
  
     }
     shinyApp(ui,server)
  </code></pre>
  
  <p>My first problem is : how can I delete the selected variable1 from inputselect() of variable2,that any of the variables has been chosen for variable1 does not appear in selectinput() of variable2 and any of them that has been chosen for variable2 does not appear in the list of selectinput() for variable3.In other words,the 3 variables should not be equal at all.They have to be different.</p>
  
  <p>The second one:I am a little confused about the usage of reactive() function and if I used it correctly,what is the correct form of ui and server for my purpose?</p>
  
  <p>Any help or solution would be greatly appreciated.If any more information about my question is needed,I'll be answering. </p>