【发布时间】:2019-03-21 22:00:07
【问题描述】:
我正在使用基于 PostgreSQL 空间数据库的 Leaflet 地图构建一个闪亮的应用程序。
我成功将空间数据导入到 SpatialPolygonDataFrame 并显示在 Leaflet 小部件上。
我正在尝试使用 RenderTable 输出显示来自 SpatialDataFrame 的数据,但它不起作用,即使使用 as.data.frame(spatialdataframe) 转换它也是如此。 因此这种转换足以显示带有 view()、kable() 或其他显示函数的表格,但在 Shiny 中则不行。
我应该进行另一次转换吗?有人有想法吗?
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)
【问题讨论】:
-
它不完全确定你在做什么(并且没有要测试的数据集)但是你已经在你的服务器中使用了 renderDataTable 所以你不使用 tableOutput 来渲染Ui 中的表。创建minimal reproducible example 的一件事是从您的示例代码中消除与问题无关的所有内容。如果去掉地图渲染,你还会遇到问题吗?
-
将
ui中的tableOutput(as.data.frame(sample_test1))更改为dataTableOutput('table'),看看是否有效