小叶标记在r闪亮的tabsetPanel中消失(当在移动设备上时)



我正在开发一个使用传单包的Shiny应用程序。我的传单地图嵌入在一个选项卡面板中,第一个选项卡显示一个绘图,当你点击第二个选项卡时,你会看到带有标记的传单地图。只要我在电脑上,一切都很好。

然而,当我在手机上打开我闪亮的应用程序时,我可以点击第二个选项卡,看到带有标记的地图。但当我切换回第一个选项卡(图1(,再次向下和向上滚动,然后单击第二个选项卡时,传单标记已经消失,地图只显示了一部分。

这是个虫子吗?

这里有一个非常简单的脚本示例:

library(shiny)
library(dplyr)
library(ggplot2)
library(leaflet)

df <- read.csv(textConnection(
"name,Lat,Long,total
Item1,36.879872,-85.335353,231
Item2,35.445454,-84.384953,123
Item3,36.395842,-85.452312,321
Item4,37.989796,-86.233434,123
Item5,38.857421,-87.342342,213"
))

ui <- fluidPage(
fluidRow(
column(8,
h1("First Headline"),
tabsetPanel(type = "tabs",
tabPanel("plot1", plotOutput("plot1")),
tabPanel("view map", leafletOutput("map"))
) 
), # col end
), # row end
fluidRow(
column(8,
h1("Another Headline"), plotOutput("plot2"),
), # col end
), # row end
) # fluidpage end

server <- function(input, output, session) {

# render plot1
output$plot1 <- renderPlot({
df %>% ggplot(aes(x = name, y = total, fill = total)) + geom_col()
}, res = 96)
# render leaflet
output$map <- renderLeaflet({
leaflet(df) %>% addProviderTiles(providers$OpenStreetMap) %>%
addCircleMarkers(lng = ~Long, lat = ~Lat) 
})

# render plot2
output$plot2 <- renderPlot({
df %>% ggplot(aes(y = Long, x = Lat)) + geom_point()
}, res = 96, height = 700)

}
shinyApp(ui, server)

我通过添加observeEvent解决了这个问题。传单现在在切换到第二个选项卡时呈现。

library(shiny)
library(dplyr)
library(ggplot2)
library(leaflet)

df <- read.csv(textConnection(
"name,Lat,Long,total
Item1,36.879872,-85.335353,231
Item2,35.445454,-84.384953,123
Item3,36.395842,-85.452312,321
Item4,37.989796,-86.233434,123
Item5,38.857421,-87.342342,213"
))

ui <- fluidPage(
fluidRow(
column(8,
h1("First Headline"),
tabsetPanel(id = "tabs", type = "tabs",
tabPanel(value = "tab1", "plot1", plotOutput("plot1")),
tabPanel(value = "tab2", "view map", leafletOutput("map"))
) 
), # col end
), # row end
fluidRow(
column(8,
h1("Another Headline"), plotOutput("plot2"),
), # col end
), # row end
) # fluidpage end

server <- function(input, output, session) {

# render leaflet second tab is active
observeEvent(input$tabs,{
if(input$tabs == "tab2")
output$map <- renderLeaflet({
leaflet(df) %>% addProviderTiles(providers$OpenStreetMap) %>%
addCircleMarkers(lng = ~Long, lat = ~Lat) 
})
})

# render plot1
output$plot1 <- renderPlot({
df %>% ggplot(aes(x = name, y = total, fill = total)) + geom_col()
}, res = 96)
# render plot2
output$plot2 <- renderPlot({
df %>% ggplot(aes(y = Long, x = Lat)) + geom_point()
}, res = 96, height = 700)

}
shinyApp(ui, server)

最新更新