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 as.data.frame(spatialdataframe). I get this warning :
Warning in if (!is.na(attribValue)) { :
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(
titlePanel("AgriPAG"),
sidebarLayout(
mainPanel(
tabsetPanel(
tabPanel(leafletOutput("m",width = "100%", height = 1000)),
tabPanel(tableOutput(as.data.frame(sample_test1)))
)
),
sidebarPanel("curseur")
)
)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)
m
})output$table <- renderDataTable(as.data.frame(sample_test1))
}
shinyApp(ui = ui, server = server)