title: Working with shiny's selectizeInput and updateSelectizeInput inside renderUI
body: <p>My basic <code>shiny</code> <code>app</code> example has a <code>data.frame</code> of 20,000 genes, each with an effect and p.value numerical values:</p>
  <pre><code>set.seed(1)
  df &lt;- data.frame(gene = paste0(&quot;g&quot;,1:20000), effect = rnorm(20000), p.value = runif(20000,1,0), stringsAsFactors = F)
  </code></pre>
  <p>And my <code>app</code> has two output options to display:</p>
  <ol>
  <li>A volcano plot, which is a scatter plot of <code>-log10(df$p.value)</code> vs. <code>df$effect</code></li>
  <li>The same as option 1, but allowing the user to select multiple genes to be highlighted in red in the volcano plot</li>
  </ol>
  <p>And I'd like the list of genes (to select from) only to appear if option 1 was selected by the user.</p>
  <p>Having a <code>renderUI</code> within in the <code>server</code> where in the <code>selectInput</code> the <code>choices</code> argument has all 20,000 genes is too slow, so I followed <a href="https://shiny.rstudio.com/articles/selectize.html" rel="nofollow noreferrer">this tutorial</a> using <code>selectizeInput</code> and <code>updateSelectizeInput</code>.</p>
  <p>Below is my <code>app</code> code, where I'm defining the <code>selectizeInput</code> within the ui and the <code>updateSelectizeInput</code> within the <code>server</code>.</p>
  <p>It doesn't do what I want:</p>
  <ol>
  <li>If the <code>label</code> variable isn't defined in <code>selectizeInput</code> it throws the error: <code>Error in dots_list(...) : argument &quot;label&quot; is missing, with no default</code>. But if I do define it, that box appears by default rather than conditioned on the user selecting option 2.</li>
  <li>The list that appears does not allow selecting from it.</li>
  <li>My app doesn't display the rendered plot.</li>
  </ol>
  <pre><code>suppressPackageStartupMessages(library(dplyr))
  suppressPackageStartupMessages(library(shiny))
  suppressPackageStartupMessages(library(shinyjs))
  suppressPackageStartupMessages(library(DT))
  suppressPackageStartupMessages(library(readr))
  suppressPackageStartupMessages(library(plotly))
  suppressPackageStartupMessages(library(rmarkdown))
  
  volcanoPlot &lt;- function(df,selected.gene.set=NULL)
  {
    plot.df &lt;- df %&gt;%  dplyr::mutate(log10.p.value = -log10(p.value))
    plot.df &lt;- cbind(plot.df,purrr::imap(plot.df, ~ paste(.y, .x, sep=&quot;: &quot;)) %&gt;%
                       dplyr::as_tibble() %&gt;%
                       tidyr::unite(text, sep=&quot;\n&quot;))
    if(!is.null(selected.gene.set)){
      plot.df$group &lt;- &quot;unselected&quot;
      plot.df$group[which(plot.df$gene %in% selected.gene.set)] &lt;- &quot;selected&quot;
      plot.df$group &lt;- factor(plot.df$group,levels=c(&quot;unselected&quot;,&quot;selected&quot;))
      volcano.plot &lt;- plotly::plot_ly(type='scatter',mode=&quot;markers&quot;,marker=list(size=5),color=plot.df$group,colors=c(&quot;lightgray&quot;,&quot;darkred&quot;),x=plot.df$effect,y=plot.df$log10.p.value,text=plot.df$text,hoverinfo=&quot;text&quot;,showlegend=F) %&gt;%
        plotly::layout(xaxis=list(title=&quot;Effect&quot;,zeroline=F),yaxis=list(title=&quot;-log10(P-value)&quot;,zeroline=F))
    } else{
      volcano.plot &lt;- plotly::plot_ly(type='scatter',mode=&quot;markers&quot;,marker=list(size=5,color=&quot;gray&quot;),x=plot.df$effect,y=plot.df$log10.p.value,text=plot.df$text,hoverinfo=&quot;text&quot;,showlegend=F) %&gt;%
        plotly::layout(xaxis=list(title=&quot;Effect&quot;,zeroline=F),yaxis=list(title=&quot;-log10(P-value)&quot;,zeroline=F))
    }
    return(volcano.plot)
  }
  
  output.choices &lt;- c(&quot;&quot;,&quot;Volcano Plot&quot;,&quot;Highlighted Gene Set Volcano Plot&quot;)
  set.seed(1)
  df &lt;- data.frame(gene = paste0(&quot;g&quot;,1:20000), effect = rnorm(20000), p.value = runif(20000,0,1), stringsAsFactors = F)
  
  server &lt;- function(input, output, session)
  {
    output$selected.gene.set &lt;- renderUI({
      req(input$outputType == &quot;Highlighted Gene Set Volcano Plot&quot;)
      updateSelectizeInput(session,&quot;selected.gene.set&quot;,&quot;Select Genes to Highlight&quot;,choices=unique(df$gene),multiple=T)
    })
  
    volcano.plot &lt;- reactive({
      req(input$outputType)
      if(input$outputType == &quot;Volcano Plot&quot;){
        volcano.plot &lt;- volcanoPlot(df=df)
      } else{
        req(input$selected.gene.set)
        volcano.plot &lt;- volcanoPlot(df=df,selected.gene.set=input$selected.gene.set)
      }
      return(volcano.plot)
    })
  
    output$out.plotly &lt;- plotly::renderPlotly({
      volcano.plot()$volcano.plot
    })
  }
  
  ui &lt;- fluidPage(
    sidebarLayout(
      sidebarPanel(
        tags$head(
          tags$style(HTML(&quot;.multicol {-webkit-column-count: 3; /* Chrome, Safari, Opera */-moz-column-count: 3; /* Firefox */column-count: 3;}&quot;)),
          tags$style(type=&quot;text/css&quot;, &quot;#loadmessage {position: fixed;top: 0px;left: 0px;width: 100%;padding: 5px 0px 5px 0px;text-align: center;font-weight: bold;font-size: 100%;color: #000000;background-color: #CCFF66;z-index: 105;}&quot;),
          tags$style(type=&quot;text/css&quot;,&quot;.shiny-output-error { visibility: hidden; }&quot;,&quot;.shiny-output-error:before { visibility: hidden; }&quot;)),
        conditionalPanel(condition=&quot;$('html').hasClass('shiny-busy')&quot;,tags$div(&quot;In Progress...&quot;,id=&quot;loadmessage&quot;)),
        selectInput(&quot;outputType&quot;, &quot;Output Type&quot;, choices = output.choices),
        selectizeInput(inputId='selected.gene.set',label=&quot;Select Genes to Highlight&quot;,choices=NULL)
      ),
      mainPanel(
        plotly::plotlyOutput(&quot;out.plotly&quot;)
      )
    )
  )
  
  shinyApp(ui = ui, server = server)
  
  </code></pre>