In Shiny, update DataTable with new values from user input

萝らか妹 提交于 2019-12-04 12:06:23

You can render the result of eventReactive, where you return the updated dataset. Don't forget to use <<- to modify the global dataset as well:

server = function(input,output){
  output$table <- renderDataTable( df())
  df <- eventReactive(input$goButton, {
    if(input$NewID!="" && !is.null(input$NewVal) && input$goButton>0){
      newrow = data.table(id = input$NewID,
                        val = input$NewVal)
      mydata <<- rbind(mydata, newrow)
      }
    mydata
  }, ignoreNULL = FALSE)
}

You should use replaceData() function from package DT. Example:

...
  dataTableOutput("OPreview"),
  actionButton("BRefresh","Refresh"),
...

in server part(assuming ds is a dataset to show):

output$OPreview<-renderDataTable({ ds })

onclick("BRefresh",{
  proxy=dataTableProxy("OPreview")
  replaceData(proxy,ds)
})

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!