shp file in the funtion


In my shiny application I call the funtion tab (see an extract below) that uses .shp file.
My issue is with the variable varcode.
In my shiny interface I put the value of the varcode (=toto) and I have the error message below :

Error:'names' attribute [4] must be the same length as the vector [2]

car = .shp file
varcode = interface variable

Extract of my function


f<- readShapeSpatial(car)

but if I put manually the variable toto all things it's ok

Thanks in advance to your help!

Hi @sbl_bah! Welcome!

I'm afraid there's not enough information here to know exactly why you're getting this error. Speaking very generally, the error is happening because varcode has the wrong length (it has length 2, here). I'm not at all sure I understand what varcode is supposed to be here, but it sounds like maybe you're expecting it to hold only a single value, rather than two values?

The next step is to work backwards to the code that calls this function and supplies the varcode argument to see why something unexpected is getting passed in. You might start by taking a look at the debugging resources linked here: Shiny debugging and reprex guide

Beyond that, your best bet for getting more specific help is to construct a small reproducible example that has the same problem — see the guide above for some pointers on how to do that when working with shiny.

1 Like

Thanks to your help!
I found the solution of my issue.
row.names(contig)<-f@data[ ,varcode] insted of row.names(contig)<-f@data$varcode
That's ok
Nice B-)