Updating data in a brilliant application without updating the entire application

I have an application for building real-time data visualization with the R shiny library. I periodically reload data from a file using the reactivePoll function. What I don't like is that whenever the data is reloaded, the whole application is updated.

So, if I have DT table output with a selection, and I use this input$table_rows_selected , it is reset to NULL whenever information that is not user friendly is reloaded.

Is it possible to change the output at all without interrupting the user?

UPDATE

Can this be done with any other package for displaying tables - googleVis or another?

Working example.

 library(shiny) library(DT) runApp(shinyApp( ui = fluidPage(dataTableOutput('table')), server = function(input, output, session) { pollData <- reactivePoll(4000, session, checkFunc = function(){ Sys.time() }, valueFunc = function(){ data.frame(id = sample(letters[1:3]), a = runif(3), b = runif(3), c = runif(3)) }) output$table <- renderDataTable({pollData()}) proxy <- dataTableProxy('table') observeEvent(pollData(), { selectRows(proxy, input$table_rows_selected) })} )) 

I took this example from @NicE's answer and added the id column. The fact is that @NicE's answer is fine if you need to select a specific line when this line is identified by the line number.

Now suppose I need a string to select when this string is identified by some id value. That is, if I select a row with id equal to b, then the next time I reload the data, I want the row to be selected with the same id value.

+5
source share
1 answer

You can use dataTableProxy to select rows when the created datable is created after updating pollData . Here is an example, a dataframe is updated every day:

 library(shiny) library(DT) ui <- fluidPage(dataTableOutput("table")) server <- function(input,output,session){ values <- reactiveValues() pollData <- reactivePoll(4000, session, checkFunc=function(){ Sys.time() }, valueFunc=function(){ data.frame(a=sample(c("a","b","c"),3),b=runif(3),c=runif(3),stringsAsFactors = F) }) output$table <- renderDataTable({ pollData()}) observe({ values$selected <- pollData()$a[input$table_rows_selected] }) proxy = dataTableProxy('table') observeEvent(pollData(),{ selectRows(proxy, which(pollData()$a %in% values$selected)) }) } shinyApp(ui,server) 

Update: in the above code, when the data changes, the selected rows are those that have the same first column as before.

+5
source

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


All Articles