title: Why does the code only work partially when using multiple tabs?
body: <p>I previously posted a question for an app idea <a href="https://stackoverflow.com/questions/58902374/exporting-texts-and-datatable-from-shiny-to-pdf">here</a>.  I decided to add on something similar within the same app so that each tab would have similar function but would deal with different sets of drug instructions.  I tried to follow the query and solution posted <a href="https://stackoverflow.com/questions/44222796/shiny-with-multiple-tabs-and-different-sidebar-in-each-tab">here</a> but somehow lost most of the outputs of <code>mainPanel</code>.
  This is the code that incorporates two tabs</p>
  
  <pre><code>library(tidyverse)
  library(shiny)
  library(shinythemes)
  library(xtable)
  
  
  insulin &lt;- readRDS("insulin.rda")
  
  # User Interface
  
  ui &lt;- fluidPage(
    titlePanel("Pre-operative Advice on Long-term Medications for Patients Undergoing Elective Surgery - version 0.1"),
  
  
  
    tabsetPanel(
      tabPanel("Long-term Medications", fluid = TRUE,
              sidebarLayout(
                sidebarPanel(
                  selectInput("specialty", "Choose which surgical subspecialty",
                              c("Major Orthopaedic Arthroplasty or Revision" = "ortho",
                                "All other specialties" = "other"),
                              selected = "All other specialties"),
  
                ),
                mainPanel(
                  br(),
  
                  uiOutput("drugs_sel"),
  
                  h3(textOutput(outputId = "px_name")),
  
                  br(),
  
                  h4(textOutput(outputId = "dob")),
  
                  br(),
  
                  tableOutput("drugs_table")
  
                )
              )
  
      ),
  
      tabPanel("Insulin", fluid = TRUE,
        sidebarLayout(
          sidebarPanel(
  
  
            selectInput("DM", "What type of diabetes does patient have?",
                        c("Type One" = "Type 1",
                          "Type Two on Insulin" = "Type 2"),
                        selected = "Type One"),
  
            selectInput("time", "Is patient on morning or afternoon list?",
                        c("Morning List" = "AM",
                          "Afternoon List" = "PM"),
                        selected = "Morning"),
            checkboxGroupInput("class", "Which type(s) of insulin is patient on?",
                               c("Long and Intermediate acting",
                                 "Pre-Mixed",
                                 "Rapid or Short acting"))
          ),
          mainPanel(
            br(),
  
            helpText("Choose from the type(s) of insulin from left panel before typing",
                     "Please ensure the type(s) of insulin are correct before proceeding"),
  
            uiOutput("insulin_sel"),
  
            h3(textOutput(outputId = "px_name")),
  
            br(),
  
            h4(textOutput(outputId = "dob")),
  
            br(),
  
            tableOutput("insulin_table"),
  
            radioButtons('format', 'Document format', c('PDF'),
                         inline = TRUE),
            downloadButton('downloadReport')
          )
  
        )
  
      )
  
  
    )
  )
  
  
  
  server &lt;- function(input, output){
    my_insulin_table &lt;- reactive({
      insulin_subset &lt;- insulin %&gt;% filter(DM == input$DM,
                                           Time == input$time,
                                           Class %in% input$class)
      tab &lt;- insulin_subset %&gt;% filter(Name %in% input$name) %&gt;% select(Class, Name, Plan)
      return(tab)
    })
  
    my_drugs_table &lt;- reactive({
      drugs_subset &lt;- drugsUI %&gt;% filter(Specialty == input$specialty)
  
      drug_tab &lt;- drugs_subset %&gt;% select(Name, Recommnedations)
      return(drug_tab)
    })
  
    output$px_name &lt;- renderText({input$px_name})
  
    output$dob &lt;- renderText({input$dob})
  
    output$drugs_sel &lt;- renderUI({
      drugs_subset &lt;- drugsUI %&gt;% filter(Specialty == input$specialty)
  
      selectizeInput("drug", "Type in name of drug",
                     choices = lsit("Type in name of drug" = "",
                                    "Names" = drugs_subset$Name),
                     selected = NULL,
                     multiple = TRUE,
                     options = NULL)
  
    })
  
    output$drug_table &lt;- renderTable({
      xtable(my_drugs_table())
    })
  
    output$insulin_sel &lt;- renderUI({
  
      insulin_subset &lt;- insulin %&gt;% filter(DM == input$DM, 
                                           Time == input$time, 
                                           Class %in% input$class)
  
      selectizeInput("name", "Type in name of insulin",
                     choices = list("Begin typing name of insulin" = "", 
                                    "Names" = insulin_subset$Name), 
                                    selected = NULL, 
                                    multiple = TRUE,
                                    options = NULL)
    })
  
    output$insulin_table &lt;- renderTable({
      xtable(my_insulin_table())
    })
  
    output$downloadReport &lt;- downloadHandler(
      filename = function() {("insulin-instructions.pdf")
        # paste('my-report', sep = '.', switch(
        #   input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
        # ))
      },
  
      content = function(file) {
        src &lt;- normalizePath('report_insulin.Rmd')
  
        # temporarily switch to the temp dir, in case you do not have write
        # permission to the current working directory
        owd &lt;- setwd(tempdir())
        on.exit(setwd(owd))
        file.copy(src, 'report_insulin.Rmd', overwrite = TRUE)
  
        library(rmarkdown)
        out &lt;- render('report_insulin.Rmd', 
                      params = list(name = input$px_name, dob = input$dob),
                      'pdf_document')
        file.rename(out, file)
      }
    )
  
  }
  
  shinyApp(ui = ui, server = server)
  
  </code></pre>
  
  <p>If I remove the <code>tabPanel</code> named <code>"Long-term Medications"</code>, the other tabPanel seems to work again.
  Would anyone be able to shed any light as to why this would be?  I am very new to this so some explanation would be helpful for my own education.</p>
  
  <p>These are the <code>dput()</code> on which this is based:</p>
  
  <pre><code>dput(tail(drugsUI, 20))
  structure(list(Specialty = c("other", "other", "other", "other", 
  "other", "other", "other", "other", "other", "other", "other", 
  "other", "other", "other", "other", "other", "ortho", "ortho", 
  "ortho", "ortho"), Name = c("Ulipristal", "Ursodeoxycholic acid", 
  "Valproic acid", "Valsartan", "Varenicline", "Venlafaxine", "Verapamil", 
  "Vigabatrin", "Vildagliptin", "Warfarin", "Zafirlukast", "Zolendronate", 
  "Zolpidem", "Zopiclone", "Zotepine", "Zuclopenthixol", "Aspirin only", 
  "Clopidogrel or other -grels only", "NSAIDS for pain (e.g. ibuprofen, naproxen, diclofenac)", 
  "Dual Antiplatelet (Aspirin AND Clopidogrel)"), Recommendations = c("Continue –may not be needed post op if removing uterine fibroids", 
  "Continue", "Continue", "Omit on day of surgery if used for high blood pressure, continue for congestive heart failure", 
  "Continue", "Continue – but avoid pethidine use", "Continue", 
  "Continue", "See Diabetes Guideline. Usually omitted morning of surgery", 
  "See Anticoagulation/Antiplatelet Guideline", "Continue", "Continue - but may be safely omitted if due day of procedure", 
  "Continue", "Continue", "Continue", "Continue", "Stop 7 days before surgery", 
  "See below graphic", "Stop 2 days before surgery", "Review medical indication - Surgery should be deferred until patient on single antiplatelet (i.e. Aspirin OR Clopidogrel; if not possible discuss with sugeon, anaesthetist and cardiologist about plan.  Ideally continue at least aspirin"
  )), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"
  ))
  </code></pre>
  
  <pre><code>structure(list(DM = c("Type 2", "Type 2", "Type 2", "Type 2", 
  "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", 
  "Type 2", "Type 2", "Type 2", "Type 1", "Type 1", "Type 1", "Type 1", 
  "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", 
  "Type 1", "Type 1", "Type 1", "Type 2", "Type 2", "Type 2", "Type 2", 
  "Type 2", "Type 2", "Type 2", "Type 2", "Type 1", "Type 1", "Type 1", 
  "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", "Type 2", "Type 2", 
  "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", "Type 2", 
  "Type 2", "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", "Type 1", 
  "Type 1", "Type 1", "Type 1", "Type 1"), Time = c("AM", "AM", 
  "AM", "AM", "AM", "AM", "AM", "PM", "PM", "PM", "PM", "PM", "PM", 
  "PM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "PM", "PM", "PM", 
  "PM", "PM", "PM", "PM", "AM", "AM", "AM", "AM", "PM", "PM", "PM", 
  "PM", "AM", "AM", "AM", "AM", "PM", "PM", "PM", "PM", "AM", "AM", 
  "AM", "AM", "AM", "PM", "PM", "PM", "PM", "PM", "AM", "AM", "AM", 
  "AM", "AM", "PM", "PM", "PM", "PM", "PM"), Class = c("Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Long and Intermediate acting", 
  "Long and Intermediate acting", "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", 
  "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", 
  "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", 
  "Pre-Mixed", "Pre-Mixed", "Pre-Mixed", "Rapid or Short acting", 
  "Rapid or Short acting", "Rapid or Short acting", "Rapid or Short acting", 
  "Rapid or Short acting", "Rapid or Short acting", "Rapid or Short acting", 
  "Rapid or Short acting", "Rapid or Short acting", "Rapid or Short acting", 
  "Rapid or Short acting", "Rapid or Short acting", "Rapid or Short acting", 
  "Rapid or Short acting", "Rapid or Short acting", "Rapid or Short acting", 
  "Rapid or Short acting", "Rapid or Short acting", "Rapid or Short acting", 
  "Rapid or Short acting"), Name = c("Abasaglar", "Lantus", "Levemir", 
  "Toujeo", "Tresiba", "Insulatard", "Humulin I", "Abasaglar", 
  "Lantus", "Levemir", "Toujeo", "Tresiba", "Insulatard", "Humulin I", 
  "Abasaglar", "Lantus", "Levemir", "Toujeo", "Tresiba", "Insulatard", 
  "Humulin I", "Abasaglar", "Lantus", "Levemir", "Toujeo", "Tresiba", 
  "Insulatard", "Humulin I", "Humulin M3", "Novomix 30", "Insuman Comb 15/25/50", 
  "Humalog Mix 25/50", "Humulin M3", "Novomix 30", "Insuman Comb 15/25/50", 
  "Humalog Mix 25/50", "Humulin M3", "Novomix 30", "Insuman Comb 15/25/50", 
  "Humalog Mix 25/50", "Humulin M3", "Novomix 30", "Insuman Comb 15/25/50", 
  "Humalog Mix 25/50", "Novorapid/Fiasp", "Humalog", "Apidra", 
  "Humulin S", "Actrapid", "Novorapid/Fiasp", "Humalog", "Apidra", 
  "Humulin S", "Actrapid", "Novorapid/Fiasp", "Humalog", "Apidra", 
  "Humulin S", "Actrapid", "Novorapid/Fiasp", "Humalog", "Apidra", 
  "Humulin S", "Actrapid"), Plan = c("Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Usual dose at usual time", "Usual dose at usual time", "Usual dose at usual time", 
  "Half usual morning dose taken with a sugary drink at 7am", "Half usual morning dose taken with a sugary drink at 7am", 
  "Half usual morning dose taken with a sugary drink at 7am", "Half usual morning dose taken with a sugary drink at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a sugary drink at 7am", "Half usual morning dose taken with a sugary drink at 7am", 
  "Half usual morning dose taken with a sugary drink at 7am", "Half usual morning dose taken with a sugary drink at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Omit breakfast dose", "Omit breakfast dose", "Omit breakfast dose", 
  "Omit breakfast dose", "Omit breakfast dose", "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Half usual morning dose taken with a light breakfast at 7am", 
  "Omit breakfast dose", "Omit breakfast dose", "Omit breakfast dose", 
  "Omit breakfast dose", "Omit breakfast dose", "Usual morning dose taken with a light breakfast at 7am, oral fluids until 11am, omit lunchtime dose", 
  "Usual morning dose taken with a light breakfast at 7am, oral fluids until 11am, omit lunchtime dose", 
  "Usual morning dose taken with a light breakfast at 7am, oral fluids until 11am, omit lunchtime dose", 
  "Usual morning dose taken with a light breakfast at 7am, oral fluids until 11am, omit lunchtime dose", 
  "Usual morning dose taken with a light breakfast at 7am, oral fluids until 11am, omit lunchtime dose"
  )), row.names = c(NA, -64L), class = c("tbl_df", "tbl", "data.frame"
  ))
  </code></pre>