0
votes

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

I succeeded to import spatial data into SpatialPolygonDataFrame and to display it on Leaflet widget.

I am trying to display the data from the SpatialDataFrame with a RenderTable output, but its not working, even by converting it with as.data.frame(spatialdataframe). Therefore this conversion is enough to dispay the table with view(), kable() or other display functions, but not in Shiny.

Should I make another conversion? Anyone got an idea?

    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)
1
It'm not completely sure what you are doing (and don't have a data set to test on) but you've already used renderDataTable in your server so you don't use tableOutput to render the table in the Ui. One thing for creating a minimal reproducible example is to eliminate everything not related to the problem from your example code. Do you still get the problem if you eliminate the map rendering? - Elin
Change tableOutput(as.data.frame(sample_test1)) in your ui to dataTableOutput('table') and see if it works - Wilmar van Ommeren

1 Answers

0
votes

renderDataTable does not work with tableOutput. You have to use dataTableOutput instead. In addition, you should add the correct inputId for dataTableOutput.

To get everything to work change: tableOutput(as.data.frame(sample_test1)) in your ui to dataTableOutput('table')