downloadHandler getting ignored by download button on second tab in shinyjs app

I am working on a Shiny app and have it nearly done except that one of my download buttons isn’t getting through to the downloadHandler and just downloads an HTML file of the shiny app itself. The project is big so here are, I think, the relevant parts. First, the UI has two tabs. One tab has two download buttons, the other had one. The two download buttons on the first tab work fine, but when I try to replicate their code on the second tab, I run into this problem. I have confirmed that if I remove the first tab, the button works.

Here is the UI for this second tab:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>no_compare_elements <- function() {
accepted_data_types <- c("text/csv", "text/comma-separated-values,text/plain", ".csv")
file_input_width <- "100%"
tags$div(
shinyjs::useShinyjs(),
class = "data-upload-container",
tags$div(
id = "introText_Non_Comparability",
tags$div(
fluidRow(
column(4, selectInput('timeComparisons_NC',
"Time Comparisons (click and add all that apply)",
c("T5-T4", "T5-T3", "T5-T2", "T5-T1", "T4-T3",
"T4-T2", "T4-T1", "T3-T2", "T3-T1", "T2-T1"),
width = "80%", multiple = TRUE, selected = c("T4-T1", "T4-T3"))),
column(4, selectInput('startTime_NC',
"First Time Period",
c("T1", "T2", "T3", "T4", "T5"),
width = "80%", selected = "T1")),
column(4, selectInput('endTime_NC', "Last Time Period",
c("T1", "T2", "T3", "T4", "T5"),
width = "80%", selected = "T4"))
),
fluidRow(column(12, fileInput("cond_change_trend_file", "Upload Condition file with Trend",
accept = accepted_data_types, width = file_input_width
))),
actionButton(width = "100%", "run_non_compare", "Generate Data Files", class = "btn btn-primary"),
conditionalPanel(
"false", # always hide the download button
downloadButton("downloadNC"),
)
)
)
}
</code>
<code>no_compare_elements <- function() { accepted_data_types <- c("text/csv", "text/comma-separated-values,text/plain", ".csv") file_input_width <- "100%" tags$div( shinyjs::useShinyjs(), class = "data-upload-container", tags$div( id = "introText_Non_Comparability", tags$div( fluidRow( column(4, selectInput('timeComparisons_NC', "Time Comparisons (click and add all that apply)", c("T5-T4", "T5-T3", "T5-T2", "T5-T1", "T4-T3", "T4-T2", "T4-T1", "T3-T2", "T3-T1", "T2-T1"), width = "80%", multiple = TRUE, selected = c("T4-T1", "T4-T3"))), column(4, selectInput('startTime_NC', "First Time Period", c("T1", "T2", "T3", "T4", "T5"), width = "80%", selected = "T1")), column(4, selectInput('endTime_NC', "Last Time Period", c("T1", "T2", "T3", "T4", "T5"), width = "80%", selected = "T4")) ), fluidRow(column(12, fileInput("cond_change_trend_file", "Upload Condition file with Trend", accept = accepted_data_types, width = file_input_width ))), actionButton(width = "100%", "run_non_compare", "Generate Data Files", class = "btn btn-primary"), conditionalPanel( "false", # always hide the download button downloadButton("downloadNC"), ) ) ) } </code>
no_compare_elements <- function() {
  accepted_data_types <- c("text/csv", "text/comma-separated-values,text/plain", ".csv")
  file_input_width <- "100%"
  tags$div(
    shinyjs::useShinyjs(),
    class = "data-upload-container",
    tags$div(
      id = "introText_Non_Comparability",
    tags$div(
      fluidRow(
        column(4, selectInput('timeComparisons_NC', 
                              "Time Comparisons (click and add all that apply)", 
                              c("T5-T4", "T5-T3", "T5-T2", "T5-T1", "T4-T3", 
                                "T4-T2", "T4-T1", "T3-T2", "T3-T1", "T2-T1"),
                              width = "80%", multiple = TRUE, selected = c("T4-T1", "T4-T3"))),
        column(4, selectInput('startTime_NC', 
                              "First Time Period", 
                              c("T1", "T2", "T3", "T4", "T5"), 
                              width = "80%", selected = "T1")),
        column(4, selectInput('endTime_NC', "Last Time Period", 
                              c("T1", "T2", "T3", "T4", "T5"), 
                              width = "80%", selected = "T4"))
      ),
      fluidRow(column(12, fileInput("cond_change_trend_file", "Upload Condition file with Trend",
                                    accept = accepted_data_types, width = file_input_width
      ))),
      actionButton(width = "100%", "run_non_compare", "Generate Data Files", class = "btn btn-primary"),
      
      conditionalPanel(
        "false", # always hide the download button
        downloadButton("downloadNC"),
      )
    )
  )
}

Here is the server part:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>app_server <- function(input, output, session) {
final_data<-reactiveVal()
file_name<-reactiveVal()
user_metadata <- reactiveVal()
user_metadata_file_name <- reactiveVal()
cond_change_trend_file_NR <- reactiveVal()
cond_change_trend_file_NR_fileName <- reactiveVal()
observeEvent(input$create_scripts, {
### code to observe events on the first tab
})
### this is the button on the second tab
observeEvent(input$run_non_compare, {
startTime_NC <- input$startTime_NC
endTime_NC <- input$endTime_NC
timeComparisons_NC <- input$timeComparisons_NC
fileName_NC <- input$cond_change_trend_file$name
fileName_NC <- gsub("\.csv$", "", fileName_NC)
fileName_NC <- paste0(fileName_NC, "_NR.csv")
# print(fileName_NC)
cond_change_trend_file <- readr::read_csv(input$cond_change_trend_file$datapath)
cond_change_trend_file_NR_data <- addressNonComparabilityIssues(cond_change_trend_file, c(startTime_NC, endTime_NC), timeComparisons_NC)
cond_change_trend_file_NR(cond_change_trend_file_NR_data)
cond_change_trend_file_NR_fileName(fileName_NC)
shinyjs::click("downloadNC")
})
# DOWNLOAD BUTTONS
output$downloadNC <- downloadHandler(
filename = function() {
print('here)
cond_change_trend_file_NR_fileName()
},
content = function(file) {
write.csv(cond_change_trend_file_NR(), file, row.names = FALSE)
})
output$downloadData <- downloadHandler(
filename = function() {
file_name()
},
content = function(file) {
write.csv(final_data(), file, row.names = FALSE)
})
output$downloadMetaData <- downloadHandler(
filename = function() {
user_metadata_file_name()
},
content = function(file) {
write.csv(user_metadata(), file, row.names = FALSE)
})
}
</code>
<code>app_server <- function(input, output, session) { final_data<-reactiveVal() file_name<-reactiveVal() user_metadata <- reactiveVal() user_metadata_file_name <- reactiveVal() cond_change_trend_file_NR <- reactiveVal() cond_change_trend_file_NR_fileName <- reactiveVal() observeEvent(input$create_scripts, { ### code to observe events on the first tab }) ### this is the button on the second tab observeEvent(input$run_non_compare, { startTime_NC <- input$startTime_NC endTime_NC <- input$endTime_NC timeComparisons_NC <- input$timeComparisons_NC fileName_NC <- input$cond_change_trend_file$name fileName_NC <- gsub("\.csv$", "", fileName_NC) fileName_NC <- paste0(fileName_NC, "_NR.csv") # print(fileName_NC) cond_change_trend_file <- readr::read_csv(input$cond_change_trend_file$datapath) cond_change_trend_file_NR_data <- addressNonComparabilityIssues(cond_change_trend_file, c(startTime_NC, endTime_NC), timeComparisons_NC) cond_change_trend_file_NR(cond_change_trend_file_NR_data) cond_change_trend_file_NR_fileName(fileName_NC) shinyjs::click("downloadNC") }) # DOWNLOAD BUTTONS output$downloadNC <- downloadHandler( filename = function() { print('here) cond_change_trend_file_NR_fileName() }, content = function(file) { write.csv(cond_change_trend_file_NR(), file, row.names = FALSE) }) output$downloadData <- downloadHandler( filename = function() { file_name() }, content = function(file) { write.csv(final_data(), file, row.names = FALSE) }) output$downloadMetaData <- downloadHandler( filename = function() { user_metadata_file_name() }, content = function(file) { write.csv(user_metadata(), file, row.names = FALSE) }) } </code>
app_server <- function(input, output, session) {

  final_data<-reactiveVal()
  file_name<-reactiveVal()
  user_metadata <- reactiveVal()
  user_metadata_file_name <- reactiveVal()
  cond_change_trend_file_NR <- reactiveVal()
  cond_change_trend_file_NR_fileName <- reactiveVal()

  observeEvent(input$create_scripts, {
    ### code to observe events on the first tab
  })
  
### this is the button on the second tab
  observeEvent(input$run_non_compare, {
    startTime_NC <- input$startTime_NC
    endTime_NC <- input$endTime_NC
    timeComparisons_NC <- input$timeComparisons_NC
    fileName_NC <- input$cond_change_trend_file$name
    
    fileName_NC <- gsub("\.csv$", "", fileName_NC)
    fileName_NC <- paste0(fileName_NC, "_NR.csv")
    
    # print(fileName_NC)

    cond_change_trend_file <- readr::read_csv(input$cond_change_trend_file$datapath)
    
    cond_change_trend_file_NR_data <- addressNonComparabilityIssues(cond_change_trend_file, c(startTime_NC, endTime_NC), timeComparisons_NC)
    
    cond_change_trend_file_NR(cond_change_trend_file_NR_data)
    cond_change_trend_file_NR_fileName(fileName_NC)
    
    shinyjs::click("downloadNC")
  })
  
  # DOWNLOAD BUTTONS 
  
  output$downloadNC <- downloadHandler(
    filename = function() {
      print('here)
      cond_change_trend_file_NR_fileName()
    },
    content = function(file) {
      write.csv(cond_change_trend_file_NR(), file, row.names = FALSE)
    })
  
  output$downloadData <- downloadHandler(
    filename = function() {
      file_name()
    },
    content = function(file) {
      write.csv(final_data(), file, row.names = FALSE)
    })

  output$downloadMetaData <- downloadHandler(
    filename = function() {
      user_metadata_file_name()
    },
    content = function(file) {
      write.csv(user_metadata(), file, row.names = FALSE)
    })
}

The downloadData and downloadMetaData handlers (both on the first tab) work fine but the downloadNC handler has the problem. I’ve confirmed that the filename and data are fine. The print statement within the downloadNC handler doesn’t fire at all. When I inspect the buttons in devtools, the working buttons have hrefs, but this non-working button doesn’t. For some reason it’s not getting connected to the downloadHandler. Could there be an asynchronous issue? Why does it being on the second tab matter?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật