gpt4 book ai didi

r - react table R Shiny 内的传单图

转载 作者:行者123 更新时间:2023-12-05 04:20:39 25 4
gpt4 key购买 nike

我想在可 react 表的列之一中包含 map ,每个 map 将占据表格内的一个单元格。像这样:

enter image description here

我已经试过了:

library(shiny)
library(reactable)
library(leaflet)

ui <- fluidPage(
mainPanel(
reactableOutput("table")
)
)

server <- function(input, output, session) {
df_aus <- data.frame(country = "australia",
latitude = -35.31,
longitude = 149.13)

df_belg <- data.frame(country = "belgium",
latitude = 50.83,
longitude = 4.33)

map_aus = leaflet(df_aus) %>%
addProviderTiles("CartoDB.Positron")%>%
addMarkers(
label = ~ country,
layerId = ~ country
)
map_belg = leaflet(df_belg) %>%
addProviderTiles("CartoDB.Positron")%>%
addMarkers(
label = ~ country,
layerId = ~ country
)

df <- data.frame(country = c("australia","belgium"),
values = c(10, 20),
map = c(map_aus,map_belg))

output$table <- renderReactable({
reactable(df)
})
}

shinyApp(ui, server)

然而,这会返回一个错误,即使这两个 map 都有效。我在想我可能必须为列包含一个 renderLeaflet(),但我不确定在哪里。

我也试过像这样添加 renderLeaflet():但它也不起作用。

  df <- data.frame(country = c("australia","belgium"),
values = c(10, 20),
map = c(leafletOutput('map_1'), leafletOutput('map_2'))
)

output$map_1 <- renderLeaflet(map_aus)
output$map_2 <- renderLeaflet(map_belg)

最佳答案

你需要这样做:

library(shiny)
library(reactable)
library(leaflet)

ui <- fluidPage(
mainPanel(
reactableOutput("table")
)
)

server <- function(input, output, session) {
df_aus <- data.frame(country = "australia",
latitude = -35.31,
longitude = 149.13)

df_belg <- data.frame(country = "belgium",
latitude = 50.83,
longitude = 4.33)

map_aus = leaflet(df_aus, height = "100px") %>%
addProviderTiles("CartoDB.Positron")%>%
addMarkers(
label = ~ country,
layerId = ~ country
)
map_belg = leaflet(df_belg, height = "100px") %>%
addProviderTiles("CartoDB.Positron")%>%
addMarkers(
label = ~ country,
layerId = ~ country
)
maps <- list(map_aus, map_belg)
df <- data.frame(country = c("australia","belgium"),
values = c(10, 20),
map = NA)

output$table <- renderReactable({
reactable(data = df, columns = list(
map = colDef(cell = function(value, index) {
maps[[index]]
})
), )
})
}

shinyApp(ui, server)

要定义自定义列,您需要使用colDef 并为该列定义一个函数。

enter image description here

关于r - react table R Shiny 内的传单图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74424501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com