Shiny : How to display a spatial data frame with renderTable


Hi, I am building a Shiny app with a Leaflet map based on a PostgreSQL spatialdatabase.

I succeeded to import the spatial data (shapefile) into SpatialPolygonDataFrame and to display it on Leaflet widget.

I am now trying to display the data from the SpatialDataFrame with a RenderTable output, but its not working in shiny, even by converting it with I get this warning :

Warning in if (! { :
the condition has length > 1 and only the first element will be used
Warning in charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored

Or this one whitout the conversion :

Warning: Error in as.character.default: no method for coercing this S4 class to a vector
[No stack trace available]

However this conversion is enough to dispay the table with view(), kable() or other display functions, but not in Shiny. I guess it is a datatype problem, but i didn't figured out how to fix this.
Should I make another conversion? Anyone got an idea?

My code :

ui <- fluidPage(
tabPanel(leafletOutput("m",width = "100%", height = 1000)),

server <- function(input,output, session){

data <- reactive({
x <- test1

output$mymap <- renderLeaflet({
test1 <- data()

m <- leaflet(data = sample_test1) %>%
addTiles() %>%
setView(lng=-52.3333300, lat=4.9333300 , zoom=10) %>%
addPolygons(data=sample_test1, weight=2, col="black", opacity=0.5)

output$table <- renderDataTable(


shinyApp(ui = ui, server = server)



Hi back,

I finally fixed my problem. It was absolutely not a datatype conversion problem. I had to change

tableOutput(sample_1) by dataTableOutput('table') in my .UI by I had yet made a call to renderDataTable in my .server :

output$table <- renderDataTable(sample_test1)

1 Like


Hi rlucas, that's awesome that you were able to discover a solution! Would you mind marking your response as a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

FAQ: How do I mark a solution? meta

If your question has been answered don't forget to mark the solution Folks in the future can come along and easily see what worked for you. You acknowledge the person who solved the issue. If you're the original poster and the category allows solutions to be marked there should be a little box at the bottom of replies that you can click to select that response as your "solution." Before: [image] After: [image] Based on replies by @mara


closed #4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.