【问题标题】:R Shiny : How to display a spatial dataframe with renderTableR Shiny:如何使用 renderTable 显示空间数据框
【发布时间】: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'),看看是否有效

标签: r shiny leaflet


【解决方案1】:

renderDataTable 不适用于tableOutput。您必须改用dataTableOutput。此外,您应该为dataTableOutput 添加正确的inputId

为了让一切正常工作,请更改:tableOutput(as.data.frame(sample_test1)) 在您的 uidataTableOutput('table')

【讨论】:

    猜你喜欢
    • 2013-03-08
    • 2023-04-05
    • 2023-03-24
    • 2021-08-04
    • 2021-02-11
    • 1970-01-01
    • 2021-11-15
    • 2014-01-07
    • 1970-01-01
    相关资源
    最近更新 更多