The best way to make brilliant run on internal load

I have the code below on my Brilliant server. My intention is that every time the refreshData button in the user interface is clicked, a database is requested, and this data is used in summaryPlot. Is there a way to trigger the same database query when the Shiny application first loads?

shinyServer(function(input, output, session){

  dailySummaryTable = eventReactive (input$refreshData,  {  
    temp = GetData(input$dateRange[1], input$dateRange[2])    
    return (temp)
  })  

  output$summaryPlot = renderPlot({

    summary = dailySummaryTable()

    ggplot(summary) + geom_bar(aes(x=as.factor(Class), y=Num, fill=Type), stat = 'identity')
  }) 
})

Thank!

+4
source share
1 answer

You can add an argument ignoreNull = FALSEto eventReactive. The following is a working example. Hope this helps!

shinyApp(ui,server)

library(shiny)

ui <- fluidPage(
  actionButton('refreshData','Refresh!'),
  tableOutput('summaryTable')
)

server <- function(input, output, session){

  df = eventReactive (input$refreshData, ignoreNULL = F, {  
    mtcars[sample(seq(nrow(mtcars)),5),]
  })  

  output$summaryTable = renderTable({
    head(df())
  }) 
}

shinyApp(ui,server)

Compare this to application behavior where the argument is ignoreNullnot used:

library(shiny)

ui <- fluidPage(
  actionButton('refreshData','Refresh!'),
  tableOutput('summaryTable')
)

server <- function(input, output, session){

  df = eventReactive (input$refreshData, {  
    mtcars[sample(seq(nrow(mtcars)),5),]
  })  

  output$summaryTable = renderTable({
    head(df())
  }) 
}
+2
source

Source: https://habr.com/ru/post/1695360/


All Articles