简体   繁体   中英

How to pass stateSave in Shiny when I have ui.R and Server.R file separate?

I want to pass saveState argument in my shiny server.

I found following code from https://github.com/rstudio/DT/issues/76

DTApp = function(data, ..., options = list()) {
library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    fluidRow(
     verbatimTextOutput('foo'),
     DT::dataTableOutput('tbl')
    )
  ),
  server = function(input, output, session) {
     options$ajax = list(url = dataTableAjax(session, data))
     # create a widget using an Ajax URL created above
     widget = datatable(data, server = TRUE, ..., options = options)
     output$tbl = DT::renderDataTable(widget)
     output$foo = renderPrint(str(input$tbl_state))
  }
 )
}

DTApp(iris, options = list(stateSave = TRUE))

As we can see here, They has pass stateSave in DTApp. However, I am building ui and server seperate. Rstudio is building app for me.

I have no idea, where to pass stateSave argument. I believe it should go into server, however, I am not sure.

stateSave is just an option for datatable . So change the following line

 widget = datatable(data, server = TRUE, ..., options = options)

to

 widget = datatable(data, server = TRUE, ..., options = list(stateSave = TRUE))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM