0

I want the user to click a button and then the renderDataTable function gets called

This is what I'm doing now:

The UI has this:

ui <- fluidPage(
 actionButton("tbl","Show Table"),
 DT::dataTableOutput("t_all")
)

Server:

server <- function(input, output){

summary_table_RCT <- eventReactive(input$tbl, {summary_table})

output$t_all <-
DT::renderDataTable(
  summary_table_RCT(), 
  filter = 'top',
  class = "cell-border stripe",
  rownames = FALSE,
  extensions = c("FixedColumns"),
  options = list(searchHighlight = TRUE, 
                 regex = TRUE,
                 scrollX = TRUE,
                 fixedColumns = list(leftColumns = 5)) 
)
}

shinyApp(ui, server)

Not sure why it's not working this is almost the same as some of the examples I've seen for eventReactive(). I see the button show up, but it doesn't do anything when clicked.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Jamalan
  • 482
  • 4
  • 15
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's much easier to help you if we can actually run the code. Are you sure `summary_table` has values? – MrFlick Oct 27 '20 at 22:14
  • Sorry I'm unable to share too much more because this is for work. But all the relevant elements are above. I have an action button. When clicked, I want to create a reactive dataframe, which I want rendered using the renderDataTable function. – Jamalan Oct 27 '20 at 22:33
  • If I replace `{summary_table}` with `iris` in a simple shiny app, it works just as you desire. The table appears after I press the button. I cannot replicate the problem you describe from the information given. – MrFlick Oct 27 '20 at 22:35
  • when I switch summary_table_RCT() to summary_table, it works fine, so the data is coming through, but the event reactive just doesn't seem to be returning a dataset when the button is pressed. – Jamalan Oct 27 '20 at 22:53
  • Are you sure you've typed the name of the button correctly? Unless you can create a reproducible example in your question, I'm not sure how to help. There must be something going on that's not included in what you've posted. What version of Shiny are you using? – MrFlick Oct 27 '20 at 22:56

1 Answers1

-1

Found the answer, hopefully someone who has to go through the same frustration finds this before it makes them nuts. But in a different tab in the app, another developer used a submitButton(), which basically interrupts ALL reactive events until the button is pressed. Should only only be used in very simple apps, where you only have one button.

Jamalan
  • 482
  • 4
  • 15
  • Would you mind to actually share the code or the link to the answer you mention? – FilipeTeixeira Apr 07 '21 at 11:31
  • 1
    This is the answer. Sorry, I didn't find it in another thread, I figured it out myself. Basically the submitButton() interrupts everything, don't use it ever. – Jamalan Apr 16 '21 at 02:12