我想知道是否有人知道我在Rshiny中遇到的問題的解決方案。總之,我正在尋找基於小冊子的地圖標記來更新用戶的當前標籤。理想情況下,我的小組希望用戶使用地圖在介於標籤內的統計數據練習之間進行導航(本例中不存在練習)。試圖集成updateTabsetPanel與單張標記點擊R閃亮?
這個想法是,某些建築物標記與某些標籤相關,並且用戶查看地圖,看到標記,點擊以查找更多(彈出),並且下面的標籤自動更改以使練習與標記。
我一直在試圖實現這一點,使鼠標點擊地圖標記註冊爲'updateTabsetPanel'命令的輸入,但似乎碰到了磚牆。我也嘗試在彈出窗口中實現超鏈接/ URL以將用戶重定向到正確的選項卡,但在那裏也沒有運氣。
我已經閱讀了另一個例子,在此之前尋找做同樣的事情,但尋求幫助的人只提供他們的代碼摘錄,而當我試圖按照他們得到的答案,我不能似乎讓它起作用,讓我覺得在我的代碼的其他地方可能還有另一個小問題。
我在下面提供了一個更深入的工作示例,也許有人會友好地看看並提出修復建議,或者告訴我,我所要求的Shiny/R太複雜了,而且我的時間在別處花得最好。
謝謝!
**
library(leaflet)
library(shiny)
library(dplyr)
shinyServer(function(input, output, session) {
#I've tried hyperlinking to the tab with an action link/hyperlink
##that would appear in the popup
Popcontent1 <- paste(sep = "<br/>",
actionLink("?url=inTabset/Home", "Learn about A"),
"This would be the First Marker",
"and would update the tabs to a specific tab below")
Popcontent2 <- paste(sep = "<br/>",
actionLink("link_to_tabpanel_B", "Learn about B"),
"This one would also update to another tab")
output$London <- renderLeaflet({
London <- leaflet(options = leafletOptions(zoomControl = FALSE,
minZoom = 16, maxZoom = 16)) %>%
setView(lng = 0.12783, lat =51.50741, zoom = 16)%>%
addTiles(options = providerTileOptions(opacity = 0.45)) %>%
addCircleMarkers(lng=0.12783, lat=51.50741, radius = 13,
opacity = 0.5, color = "#008B45",
popup=Popcontent1)%>% #MarkerHome
addCircleMarkers(lng=0.12774, lat=51.50700, radius = 13,
color = "#48D1CC",popup=Popcontent2) #Marker2
PopTEST <- addCircleMarkers(London, lng=0.12800, lat=51.50650,
color = "#9400D3", popup=Popcontent1) #TestMarker
})
## Attempt at making the markers in the above map interactive.
## Ideally, clicking on the markers above would change the tabs,
## meaning users click on certain building marker and get relevant tab
observe({
event <- input$London_PopTEST_click
updateTabsetPanel(session, "inTabset", selected = event$A)
})
observeEvent(input$switchtab, {
event <- input$London_PopTEST_click
updateTabsetPanel(session, "inTabset", selected = event$A)
})
})
#########UI
shinyUI(fluidPage(
titlePanel("This is the Map"),
leafletOutput("London", width = "100%", height = 600),
br(),
tabsetPanel(id = "inTabset",
tabPanel(title = "Home", id = "Home",
h4("This is the Home Tab"),
br(),
mainPanel(),
fluidRow(
column(12,
p("This would be the introductory tab.")
))),
######################################## Tab A
tabPanel("Tab A", id = "A",
h4("This tab would be the next step"),
br(),
fluidRow(
column(12,
p("This tab would be brought up by the
marker/popup click in the map above.")
))))
))
**
嗨@SBista,非常感謝你的幫助。我已經嘗試了兩種方法,兩者都很好。我花了整整一個週末的時間,但隨着你的幫助它終於有效:)我最終選擇了你建議的第一種方法,並讓用戶使用超鏈接來更改各個標籤。爲了使未來潛在讀者清晰起見,我將「link_click」參數修改爲「link2_click \」,「link3_click \」等等,並將其與mirrorEvent(輸入$ link2_click,{ } updateTabsetPanel(session,「inTabset 「,」B「)代表其他標記 – Wintermute