title: Shiny: problems with renderUI reactivity
body: <p>I have a seemingly small but tricky problem with a reactive function in a Shiny App. </p>
  
  <p>The app is designed to show a lineChart when a firm is selected, and show a bar chart of all firms when "All" is selected. For example when selecting: </p>
  
  <p>Filter by Category 1= 3 and Filter by Category 1: 2 in the ui, only 4 firms remain in the firms drop down and I want to then be able to select firm A in the firms drop down to get a line chart for firm A. </p>
  
  <p>The problem is that when i select firm A, it displays the lineChart for firm A for 1 second and then jumps back to "All". </p>
  
  <p>I think the issue lies with following line: </p>
  
  <pre><code>output$firm &lt;- renderUI({
     selectInput("firm", "Filter by Firm:",
              choices = c("All",as.character(unique(subset_data()$FIRM))))   
    })  
  </code></pre>
  
  <p>The choices I request are "All" and "firm X". It first creates the lineChart for firm X and then creates the chart as under "All". I thus tried to remove the "All" from the choices, but that did not work. </p>
  
  <p>Any help much appreciated!
  Thanks</p>
  
  <p>Here's a reproducible example: </p>
  
  <p>Create sample data first: </p>
  
  <pre><code>set.seed(1)
  df &lt;- data.frame(FIRM=rep(LETTERS[1:7],each=10), CATEG_1=rbinom(70,4,0.9),CATEG_2=rbinom(70,1,0.2),date=as.Date("2014-01-01")+1:10,y1=sample(1:100,70))
  </code></pre>
  
  <p>ShinyApp:</p>
  
  <pre><code>library(shiny)
  library(rCharts)
  library(doBy)
  library(plyr)
  
  shinyApp(ui = 
  shinyUI(pageWithSidebar(
  
  # Application title
  headerPanel("Example"),
  
             sidebarPanel(
           uiOutput("firm"),
          #  selectInput("firm", "Filter by firm:", 
          #   choices = unique(as.character(df))),
           selectInput("categ_1", "Filter by Category 1:",
                       choices = c("All",unique(as.character(df$CATEG_1)))),
           selectInput("date", "Filter by Date:", 
                       choices = c("All","Last 28 Days","Last Quarter")),
           selectInput("categ_2", "Filter by Category 2:", 
                       choices = c("All",unique(as.character(df$CATEG_2))))         
         ), #sidebarPanel
  
         mainPanel(
           h4("Example plot",style = "color:grey"),
           showOutput("plot", "nvd3")
         ) # mainPanel
       ) #sidebarLayout
   ) #shinyU
   , 
  server = shinyServer(function(input, output, session) {  
  
  subset_data &lt;- reactive({df &lt;- filter_data(df,input$firm,
                                           input$date,
                                           input$categ_1,
                                           input$categ_2)
                         shiny::validate(need(!is.null(df),"No data to display"))
                         return(df)})
  
    output$firm &lt;- renderUI({
     selectInput("firm", "Filter by Firm:",
              choices = c("All",as.character(unique(subset_data()$FIRM))))   
    })        
  
    output$plot&lt;-renderChart2({ build_plot(subset_data()) })
  
  ##############
  #below are the functions used in the code
  ##############
  
   # function for date subsetting 
  
    filter_date&lt;-function(df,dateRange="All"){
    filt &lt;- df
    td &lt;- max(as.Date(filt$date))
    if (dateRange=='Last 28 Days'){filt &lt;-filt[filt$date&gt;=(td-28),]}
    if (dateRange=='Last Quarter'){filt &lt;-filt[filt$date&gt;=(td-84),]}
    return(filt)
     }  # filter by date
  
   # function for data subsetting 
  
    filter_data&lt;-function(df,firm=NULL,dateRange="All",categ_1=NULL,categ_2=NULL)
    { 
    filt&lt;-filter_date(df,dateRange)
  
    if (!is.null(firm)) {
    if(firm!='All') {filt &lt;- filt[filt$FIRM==firm,]}
    }
    if (!is.null(categ_1)){
    if (categ_1!='All') {filt &lt;- filt[filt$CATEG_1==categ_1,]}
    } 
    if (!is.null(categ_2)) {
    if (categ_2!='All') {filt &lt;- filt[filt$CATEG_2==categ_2,]} 
    }
  
    if(nrow(filt)==0) {filt &lt;- NULL}
    return(filt)
    } # prepare data to be plotted
  
  # function to create plot
  
    build_plot &lt;- function(df) {
    plotData&lt;-df
    # If 1 partner selected, time series is shown  
    if (length(as.character(unique(plotData$FIRM)))==1) {
  
    tabledta&lt;-summaryBy(y1~FIRM+date,data=plotData,FUN=sum,keep.names=TRUE) 
  
    filler = expand.grid(FIRM=as.character(unique(df$FIRM)),
                       date=seq(min(tabledta$date),max(tabledta$date),by='1 day'))
    df = merge(filler,
             tabledta,
             by=c('date','FIRM'),
             all.x=T)
    df[is.na(df)]=0
    p &lt;- nPlot(y1 ~ date, group = 'FIRM', data = df, type = 'lineChart')
    p$chart(margin=list(left=150))
    p$yAxis(showMaxMin = FALSE)
    p$xAxis(tickFormat ="#!function(d) {return d3.time.format('%Y-%m-%d')(new Date(d * 24 * 60 * 60 * 1000));}!#")
    p
    }
    # If "All" partners are selected, barchart of Top 5 is shown
    else{
    SummaryTab&lt;-aggregate(y1~FIRM,data=plotData,FUN=sum)
    SummaryTab$rank=rank(SummaryTab$y1)
    SummaryTab$rank[SummaryTab$rank&gt;5]&lt;-6
  
    if (length(SummaryTab$rank)&gt;5) {
    #Top 5 partners in terms of y1 are shown
    top5&lt;-SummaryTab[SummaryTab$rank&lt;=5,]
    # other partners are collapsed, shown as 1 entry
  
    others&lt;-aggregate(y1~rank,data=SummaryTab,FUN=sum)  
    others&lt;-others[others$rank==6,]
    others$FIRM&lt;-"Others"
  
    # Create the summarytable to be plotted
    plotData=rbind(top5,others)}
  
    tabledta&lt;-summaryBy(y1~FIRM,data=plotData,FUN=sum,keep.names=TRUE) 
    tabledta&lt;-arrange(tabledta,y1) 
    #   if(is.null(tabledta)) {print("Input is an empty string")}
  
    p &lt;- nPlot(y1 ~ FIRM,data = tabledta, type = 'multiBarHorizontalChart')    
    p$chart(margin=list(left=150))
    p$yAxis(showMaxMin = FALSE)
    p
    }
  
    }
    }) #shinyServer
    ) 
  </code></pre>