-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Accepting NULL
as an input
#288
Comments
Would returning library(shiny)
ui <- fluidPage(
reactable::reactableOutput("table")
)
server <- function(input, output, session) {
output$table <- reactable::renderReactable({
data <- NULL
if (is.null(data)) {
return(NULL)
}
reactable::reactable(data)
})
}
shinyApp(ui, server) Otherwise, having Or alternatively, it is possible to render an empty table with an empty data frame if you know the columns up front, e.g.: library(shiny)
ui <- fluidPage(
reactable::reactableOutput("table")
)
server <- function(input, output, session) {
data <- reactive(data.frame(num = numeric(0), chr = character(0)))
output$table <- reactable::renderReactable({
reactable::reactable(data())
})
}
shinyApp(ui, server) |
As far as I know there's no official documentation about NULL values in render functions, but I just find it convenient that some functions "just work" and do what I want them to do when given NULL. If it seems like it'll complicate the internals and create messy code then don't worry about it, it was merely a suggestion to think about and it looks like you've now thought about it :) |
When building shiny apps, sometimes you have a dataset that starts off as
NULL
. Often we usereq()
to avoid passing that data into thereactable()
, but it would also be good ifreactable()
didn't fail when receiving null.Example:
Rather than an error, I would expect the above app to just not show a table (for reference,
DT
works this way)The text was updated successfully, but these errors were encountered: