datatable - How to upload/import a file in the new R shiny version 0.12 using DT package -


i have updated shiny version 0.12 , started use dt package (finding bit difficult use have anyway). trying upload or import file. server code:

 shinyserver(function(input, output, session) {      datasetinput <- reactive({       infile <- input$fileinput       if(is.null(infile))         return(null)       read.table(infile$datapath,header=input$header,sep=input$sep,check.names=f)     })      output$table = dt::renderdatatable(datasetinput(), server = true)     })      # tried following code same error & warning:     # output$table <- dt::renderdatatable({     #    dt::datatable(datasetinput())     # },server=true) 

this error getting:

error in datatable(instance, ...) :    'data' must either matrix or data frame 

and following warning, despite using server = true:

warning in run(timeoutms) :   seems data big client-side datatables. may consider server-side processing: http://rstudio.github.io/dt/server.html  

i know basic, couldn't find example uses dt package import data file. more questions pop sure, because starting move 0.11 0.12.

your code fine. sure you're updated absolute latest shiny , dt? both of them have been updated pretty heavily past couple weeks, make sure install github version. guess 1 of packages not date. note new version don't need specify server = true that's new default.

here's code used , able read file , display it. it's simplification code because didn't want implement header , sep inputs. next time please include full source code including ui make easier , more reproducible :)

runapp(shinyapp(   ui = fluidpage(     fileinput("fileinput", "choose file"),     dt::datatableoutput("table")   ),   server = function(input, output, session) {     datasetinput <- reactive({       infile <- input$fileinput       if(is.null(infile))         return(null)       read.csv(infile$datapath, header = true)     })      output$table = dt::renderdatatable(datasetinput())   } )) 

note see 'data' must either matrix or data frame message after choosing file goes away. because datatable trying initialized null value apparently throws error (i argue should not display silently rather have error, that's case). solve small issue, change reactive eventreactive fire once file has been chosen

runapp(shinyapp(   ui = fluidpage(     fileinput("fileinput", "choose file"),     dt::datatableoutput("table")   ),   server = function(input, output, session) {     datasetinput <- eventreactive(input$fileinput, {       infile <- input$fileinput       read.csv(infile$datapath, header = true)     })      output$table = dt::renderdatatable(datasetinput())   } )) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -