When creating a 'nonreactive' table such as the one below, is it better to create the table in the ui fluidpage, such as example 2, or to write the dataframe beforehand? Both work but I bet one is better practice than the other.
If I want to publish an app, does the data need to be called inside of the shiny code, such as example 2? I am new to shiny, so any insight would be much appreciated. Thanks!
## Example 1:
national_guidelines2023 <- data.frame(Persons = c(1, 2, 3, 4, 5, 6, 7, 8),
PovertyGuidelines = c("$14,580", "$19,720", "$24,860", "$30,000", "$35,140", "$40,280", "$45,420", "$50,560"))
ui <- fluidPage(
tableOutput("tabGuidelines")
)
server <- function(input, output) {
output$tabGuidelines <- renderTable({
national_guidelines2023
})
}
shinyApp(ui, server)
## Example 2:
ui <- fluidPage(
tableOutput("tabGuidelines")
)
server <- function(input, output) {
output$tabGuidelines <- renderTable({
national <- data.frame(Persons = c(1, 2, 3, 4, 5, 6, 7, 8),
PovertyGuidelines = c("$14,580", "$19,720", "$24,860", "$30,000", "$35,140", "$40,280", "$45,420", "$50,560"))
return(national)
})
}
shinyApp(ui, server)