r - Shiny Error: arguments imply differing number of rows -


i'm trying develop simple app fetches local classified ads kijiji website. have made similar app pretty same exact script i'm not getting error described below don't know has gone wrong script. tried think of, couldn't work.

the structure of df dataframe in server.r follows: (note have truncated values make more readable)

'data.frame':   38 obs. of  7 variables:  $ title            : chr  "baby-boy 3-6 month" ...  $ price            : num  0 6.92 8 10 10 15 15 15 20 20 ...  $ short.description: chr  "give free ..."  $ address          : chr  "calgary, ab t2z 0v6" "341 ..."  $ date             : date, format: "2014-12-05" "2014-10-28" "2014-12-05" ...  $ full.description : chr  "give free ..."  $ link             : chr  "http://www.kijiji...." 

and can replicated follows:(a sample 5 records demonstration purposes)

df <- data.frame( title= c("baby-boy 3-6 month","giggle life optimize cloth diapers & 4 layer mixed insert", "beluga baby","baby sled",  "avent sterilizer & various medela items"), price= c(0.00,  6.92,  8.00, 10.00, 10.00), short.description=c("give free staff boy 3-6 month. live in new brighton, se", "if have questions or looking order please don't hesitate call our local line 587-774-2404, toll free line 1-877-883-3069 or visit our website…","calgary! fall in love natural , freshly handmade products mama , baby. www.belugaskincare.com on facebook.com/belugaskincare free shipping in canada $25 cart!…", "yellow plastic baby sled safety seat belt tow rope dimensions: 23\" long x 14 1/2\" wide x 12\" high $10 located in willow park off southland dr. , fairmount dr. se call: 403 460 - 0978 (will not…", "avent microwave sterilizer in condition 1 avent bottle 2 medela bottles 1/2 box of unused medela pump , save bags 1bag of replaceable medela pump parts clean, smoke free home. take all…"), address=c("calgary, ab t2z 0v6","341 westvale drive, waterloo, on n2t 2m2","canada", "calgary, ab t2j 1h6, canada","calgary, ab t2w, canada"), date=c(as.date(c( "2014-12-05", "2014-10-28", "2014-12-05", "2014-12-05", "2014-12-05"))), full.description=c("give free staff boy 3-6 month. live in new brighton, se", "if have questions or looking order please don't hesitate call our local line 587-774-2404, toll free line 1-877-883-3069 or visit our website http://www.gigglelife.com/catalog/?calgary.  \renter promo code \"kijcalgary\" in comment box when ordering receive free gift order.\rthe new giggle life optimize cloth diaper affordable, effective, , comfortable. best value on market. these reusable diapers 1 size fits (7-36lbs). \rthey $6.92 each when purchase 12. please note there $1 surcharge pattern designs. \rmanufacturer’s warranty \rsupport long use diapers! \r****free shipping across canada!!**** \rall diapers new , individually packaged - never worn or washed. high quality, one-size-fits-all, pocket cloth diapers. \rall orders shipped via canada post within 24 hours of placing order. send packages expedited insurance , tracking number, provided upon shipping out. \rlooking other package sizes? have packages of 10, 24, 38 , 100 also..", "calgary! fall in love natural , freshly handmade products mama , baby. www.belugaskincare.com on facebook.com/belugaskincare free shipping in canada $25 cart! \"making life simpler , greener can better things passionate about\" - beluga skin carethis ad posted kijiji mobile app.this ad posted kijiji mobile app.", "yellow plastic baby sledsafety seat belttow ropedimensions: 23\" long x 14 1/2\" wide x 12\" high$10located in willow park off southland dr. , fairmount dr. secall: 403 460 - 0978  (will not respond texts @ land line number)   text or call: 403 463 - 1038please see other adsthis ad posted kijiji mobile app.this ad posted kijiji mobile app.","avent microwave sterilizer in condition1 avent bottle2 medela bottles1/2 box of unused medela pump , save bags1bag of replaceable medela pump partsfrom clean, smoke free home. take 10$this ad posted kijiji mobile app.this ad posted kijiji mobile app."), link= c("http://www.kijiji.ca/v-baby-clothes-3-6-months/calgary/baby-boy-3-6-month/1037502424","http://www.kijiji.ca/v-baby-bathing-changing-diapers/calgary/giggle-life-optimize-cloth-diapers-4-layer-mixed-insert/1008481541?src=topadsearch", "http://www.kijiji.ca/v-baby-bathing-changing-diapers/calgary/beluga-baby/1037483143" , "http://www.kijiji.ca/v-baby-toy/calgary/baby-sled/1037493662", "http://www.kijiji.ca/v-baby-feeding-high-chair/calgary/avent-sterilizer-various-medela-items/1037481182"  )     ) 

here's server.r. note have commented out source code avoid providing source code , delayed computation. please use df dataframe given above reproduce results:

#install required packages listofpackages= c('shiny','ggplot2','scales') newpackages= listofpackages[!(listofpackages %in% installed.packages()[,'package'])] if(length(newpackages)>0) install.packages(newpackages)  #load required packages lapply(listofpackages,require,character.only=true)  #load source code #source('c:/users/bahae.omid/google drive/my r case studies/shiny apps/kijiji app/adscraper.r',local=true)   shinyserver(function(input,output){      #create reactive function deal inputs of user     search <- reactive({        if(length(input$t)>0) {ind <- grep(input$t,df[,'title'],ignore.case = t); df <- df[ind,] }        if(length(input$d)>0) {ind <- grep(input$d,df[,'full.description'],ignore.case = t); df <- df[ind,]}        if(length(input$a)>0) {ind <- grep(input$a,df[,'address'],ignore.case = t); df <- df[ind,]}        if(input$p >=0) {ind <- df[,'price']<=input$p ; df <- df[ind,]}     })      #send searchresult table ui.r     output$searchresult <- renderdatatable({       input$action1 #triggered when button pressed       if(input$action1==0) return()        else{isolate({         transformed <- transform(search(), url = paste('<a href = ', shquote(link), '>', 'click</a>'))         transformed[-7] #remove old link column       })       }     }, option=list(autowidth=false,pagelength=100,                    columndefs = list(list(targets =c(2,5,7) -1, searchable = false),list(swidth="75px",atargets = list(4,5)))))      #allow user download data via downloadhandler     output$down <- downloadhandler(         filename='filtered.csv',         content=function(file){write.csv(search(),file,row.names=false)}     )    }) 

and here's ui.r. note have commented out image tags avoid errors when running code:

shinyui(fluidpage(      #display datatable filters on top     tags$head(tags$style("tfoot {display: table-header-group;}")),              #add title     #img(src="kijiji.gif", height = 100, width = 100),     #img(src="plus.png", height = 20, width = 20),     #img(src="plus.png", height = 20, width = 20),          #use sidebar layout     sidebarlayout(         sidebarpanel(               #add fields search , download button allow exporting search results csv.              h5('note: running app takes little while run @ startup.'),              helptext('ad title:'),              textinput('t',''),              helptext('description:'),              textinput('d',''),              helptext('address:'),              textinput('a',''),              sliderinput('p','show prices to:',min = 0,max = 10000,step = 50,value = 10000),              actionbutton('action1','search!'),               br(),              br(),              helptext('click below download results of search:'),              downloadbutton('down','download')          ),           mainpanel(         datatableoutput('searchresult')         )      )    )) 

when run app, filters seem work fine when filter returns no records data frame (i.e. 0-row dataframe), following error:

error in data.frame(structure(list(title = character(0), price = numeric(0),  :    arguments imply differing number of rows: 0, 1 

i have tested same script using rendertable opposed renderdatatable , worked fine. output in datatable format, specially able make work in identical app.

please let me know if need more clarification.

when search() returns data.frame 0 rows

paste('<a href = ', shquote(search()$url), '>', 'click</a>') 

returns

"<a href = \"\" > click</a>" 

you trying bind new column 1 row data.frame no rows. hence error message.

you can fix using like

  transformed <- transform(search()                            , link = if(length(url) > 0){                              paste('<a href = ', shquote(url), '>', 'click</a>')                            }else{                              character(0)                            }   ) 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -