title: How to correctly create a list of reactive datasets in a Shiny App?
body: <p>I currently have several different reactive datasets that are created by my Shiny app and am trying to build a function that will pull the appropriate dataset and <code>renderHTML</code>. I am currently struggling with subsetting this list of reactive datasets that I am creating.</p>
  
  <p>I have tried using a list of reactive datasets (<code>listofsurveydata</code>) below but always get the <code>Error in .subset2: no such index at level 1</code> error message.</p>
  
  <pre><code>lcSurveyDataSplit &lt;- function(panelnumber){
  
  colind &lt;- grep(input$lcstateselect[panelnumber],colnames(inputTable$data))
  
  predata &lt;- inputTable$data %&gt;%
    filter(
      grepl(search,.[[colind]]),
      is.null(input$lccategoryselect)| Category %in% input$lccategoryselect,
      is.null(input$lcsubcategoryselect)| Sub_category %in% input$lcsubcategoryselect,
      is.null(input$lcquestionselect)| Question %in% input$lcquestionselect
    )
    }
  
    lcsurveydata1 &lt;- reactive({lcSurveyDataSplit(1)})
    lcsurveydata2 &lt;- reactive({lcSurveyDataSplit(2)})
    lcsurveydata3 &lt;- reactive({lcSurveyDataSplit(3)})
    lcsurveydata4 &lt;- reactive({lcSurveyDataSplit(4)})
  
    lcSplitPanel &lt;- function(panelnumber){ # sfnumber stands for "surveyFunction number"
  
  listofsurveydata &lt;- list(lcsurveydata1(), lcsurveydata2(), lcsurveydata3(), lcsurveydata4())
  
  surveyFunction &lt;- listofsurveydata[[panelnumber]]
  
  questioncount &lt;- nrow(surveyFunction)
  
  state &lt;- grep(input$lcstateselect[panelnumber], colnames(inputTable$data))
  
  survey &lt;- character(0)
  
  i = 1
  
  while (i &lt;= questioncount) {
  
    category = surveyFunction[i,2]
    subcategory = surveyFunction[i,3]
    question = surveyFunction[i,4]
    answer = gsub("[\r\n]", "&lt;/br&gt;", surveyFunction[i,state])
  
    if (length(grep(category,survey, fixed = T)) &gt; 0) {
  
      survey &lt;- paste0(survey,"&lt;/br&gt;",
                       "&lt;/br&gt;&lt;b&gt;", subcategory, "&lt;/b&gt;",
                       "&lt;/br&gt;&lt;b&gt;", question, "&lt;/b&gt;",
                       "&lt;/br&gt;&lt;i&gt;", answer, "&lt;/i&gt;","&lt;/br&gt;")
  
    } else {
  
      survey &lt;- paste0(survey,"&lt;/br&gt;",
                       "&lt;b&gt;&lt;u&gt;",category, "&lt;/u&gt;&lt;/b&gt;",
                       "&lt;/br&gt;&lt;/br&gt;&lt;b&gt;", subcategory, "&lt;/b&gt;",
                       "&lt;/br&gt;&lt;b&gt;", question, "&lt;/b&gt;",
                       "&lt;/br&gt;&lt;i&gt;", answer, "&lt;/i&gt;","&lt;/br&gt;")
    }
  
    i = i + 1
  
  }
  
  HTML(paste0("&lt;h4&gt;&lt;b&gt;",input$lcstateselect[panelnumber],"&lt;/b&gt;&lt;/h4&gt;",survey))
  
    }
  
    output$lcstate1 &lt;- renderUI({lcSplitPanel(1)})  
    output$lcstate2 &lt;- renderUI({lcSplitPanel(2)})
    output$lcstate3 &lt;- renderUI({lcSplitPanel(3)})  
    output$lcstate4 &lt;- renderUI({lcSplitPanel(4)})
  </code></pre>
  
  <p>I have been able to narrow down the error to these two lines because the code works fine if I don't subset the data and make literal references to the datasets in <code>listofsurveydata</code>:</p>
  
  <pre><code>listofsurveydata &lt;- list(lcsurveydata1(), lcsurveydata2(), lcsurveydata3(), lcsurveydata4())
  
  surveyFunction &lt;- listofsurveydata[[panelnumber]]
  </code></pre>
  
  <p>Ideally, I don't want to create a new function for each output object so I was wondering how I should go about solving this error?</p>