So I am making a shiny app that takes multiple inputs and produces multiple plots and tables of those inputs.
Sample RenderTable code to make one table is below:
output$Table1 <-
renderTable(data.frame(Shape = c("\u25CF", "\u25B2", "\u25FC", ""),
"Genes" = c(input$custom_genes1, "Mean"),
Analysed_values = c(t(analysis1()), mean(analysis1()))),
striped = TRUE, bordered = TRUE, hover = TRUE)
Where Shape is the symbol on the plot, "Genes" are the genes selected using a selectizeInput, and analysis1() is the result of a reactive calculation defined earlier in the code.
However I have 8-9 tables that need to be displayed depending on various checkboxes etc. Rather than copy-pasting the code out and replacing all the relevant values, I wanted to make a function that I could use to quickly display all the tables, and if I needed to change the formatting or add anything later I can just edit the function rather than each table individually.
I tried making a re-usable function using the code below:
construct_table <- function(genes_select, dataset){
renderTable(data.frame(Shape = c("\u25CF", "\u25B2", "\u25FC", ""),
"Genes" = genes_select,
Analysed_values = c(t(dataset), mean(dataset))),
striped = TRUE, bordered = TRUE, hover = TRUE)
}
And then making it easier to call each table directly:
output$Table1 <- construct_table(input$custom_genes1, analysis1())
This works in that is creates the table using the initial input values, but doesn't make the table reactive.
How can I call the renderTable reactive function inside a normal function, or is there another reactive function that I have overlooked that I can nest the renderTable function inside of that works the same way as the normal function does?