答案 0 :(得分:0)
我正在尝试使用此代码,对我来说工作正常。
library(shiny)
library(leaflet)
library(shinydashboard)
pts <- data.frame(
id= letters[seq( from = 1, to = 10 )],
x = rnorm(10, mean = -93.625),
y = rnorm(10, mean = 42.0285)
)
# Define UI
ui <- fluidPage(
tabsetPanel(id='my_tabsetPanel',
tabPanel('Map1',
leafletOutput('map1')
)
)
)
server <- function(input, output, session) {
output$map1 <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(-93.65, 42.0285, zoom = 6)
})
observe({
input$my_tabsetPanel
tab1 <- leafletProxy('map1', data = pts) %>%
clearMarkers() %>%
addCircleMarkers(lng = ~x, lat = ~y, radius = 4, layerId = ~id)
})
observeEvent(input$map1_marker_click, {
tab_title <- input$map1_marker_click[1]
appendTab(inputId = "my_tabsetPanel",
tabPanel(
tab_title, #paste0("tab_",tab_title),
value = paste0("tab_",tab_title),
fluidRow(
box('test')
#tags$b("some text")
)))
updateTabsetPanel(session, "my_tabsetPanel", selected = paste0("tab_",tab_title))
})
}
shinyApp(ui = ui, server = server)