Hello,
My goal is to display query results by generating a series of tabs with a table each. The number of tabs varies with the number of rows in the dataframe returned by the database. I tried using this forum post as a reference, however it seems that the tables on all tabs display the values of the table on the final tab. Here is an example of my code:
library(shiny)
options(warn=-1)
#global variables
numTabs_g <- 1
# Define UI for data upload app ----
ui <- fluidPage(
tags$head(),
# App title ----
h1(id="title", "Example Application"),
actionButton("button","Extract information"),
tabsetPanel(id = "tabs")
)
server <- function(input, output, session) {
observeEvent(input$button,{
#get query results
queryResults <- data.frame("a"=c(1,4),"b"=c(2,5),"c"=c(3,6))
#remove old tabs
for(i in numTabs_g:1) {
removeTab("tabs", toString(i))
}
numTabs_g <<- 0
#create new tabs with tables
for(i in 1:nrow(queryResults)) {
appendTab("tabs",
tabPanel(toString(i),
fluidRow(
column(4,shinydashboard::box(
tableOutput(paste0("tabTable",i)),
title = "Values",
width = 12
)
)
)
)
)
}
numTabs_g <<- nrow(queryResults)
#populate tables
observe(
for(i in 1:nrow(queryResults)) {
output[[paste0("tabTable",i)]] <- renderTable({
data.frame("Markers" = c("A","B","C"),
"Value" = c(queryResults[i,"a"],queryResults[i,"b"],queryResults[i,"c"]))
},rownames = FALSE, colnames = FALSE)
}
)
})
}
shinyApp(ui, server)
I would expect the table on tab 1 to show {1,2,3}, but instead it shows {4,5,6}.