Shiny 使用中的FloapeProxy()更新传单打印中的标签
我正在创建一个闪亮的应用程序,其中包含一个单张图,每当用户指定某个日期范围时,该图就会更新。每当应用程序加载时,我都会显示一个初始绘图,每当用户指定特定日期并单击操作按钮执行更改时,我都会使用Proxy()更新绘图。我这里的问题是,我在绘图上有标签,每当光标悬停在县上时,都会显示摘要统计信息。这对初始绘图很有效,但标签似乎不会在用户更改日期范围时更新。有没有办法更新这些标签 以下是我正在使用的数据集示例:Shiny 使用中的FloapeProxy()更新传单打印中的标签,shiny,leaflet,Shiny,Leaflet,我正在创建一个闪亮的应用程序,其中包含一个单张图,每当用户指定某个日期范围时,该图就会更新。每当应用程序加载时,我都会显示一个初始绘图,每当用户指定特定日期并单击操作按钮执行更改时,我都会使用Proxy()更新绘图。我这里的问题是,我在绘图上有标签,每当光标悬停在县上时,都会显示摘要统计信息。这对初始绘图很有效,但标签似乎不会在用户更改日期范围时更新。有没有办法更新这些标签 以下是我正在使用的数据集示例: FIPS County lat long Count 0100
FIPS County lat long Count
01001 Autauga 32.53953 -86.64408 89
01003 Baldwin 30.72775 -87.72207 209
01005 Barbour 31.86826 -85.38713 24
01007 Bibb 32.99642 -87.12511 41
01009 Blount 33.98211 -86.56791 183
01011 Bullock 32.10031 -85.71266 10
此外,以下是我的闪亮应用程序代码:
library(ggplot2)
library(leaflet)
library(leaflet)
library(shiny)
library(shinycssloaders)
library(DT)
## Loads Data
tmp <- read.csv()
## Date Specification Function
selectdates <- function(data, start, end){
## This function allows users to specify date range
}
## Creates Initial Labels
labels <- sprintf(
"<strong>%s</strong><br/>%g Cases",
tmp$County, tmp$Count
) %>% lapply(htmltools::HTML)
## Creates Initial Map
map0 <- leaflet(data = dta) %>%
addTiles() %>%
addPolygons(
layerId = ~FIPS,
fillColor = ~ colours(Count),
weight = 1,
opacity = 0.7,
color = "white",
dashArray = '3',
fillOpacity = 0.7
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE), label = labels, labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto"))
## UI Function Begins
ui <- fluidPage(
## Application title
titlePanel("Project"),
tags$hr(),
## Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
dateRangeInput("daterange", "Date Range:",
start = as.character(Sys.Date() - 6),
end = as.character(Sys.Date()),
min = "2020-01-22",
max = Sys.Date()),
checkboxInput("checkBox", "Select all dates", FALSE),
textOutput("dateCheck"),
selectInput("typeChoice", "Data Type:", choices = c("Raw", "Percentage")),
actionButton("submitButton", "Submit", class = "btn btn-primary")
),
## Display leaflet plot of cases
mainPanel(
withSpinner(leafletOutput("casemap"), type = 4)
)
)
)
## Server Function Begins
server <- function(input, output, session) {
observe({
if (input$checkBox == TRUE){
updateDateRangeInput(session,
"daterange",
"Date Range:",
start = "2020-01-22",
end = Sys.Date(),
min = "2020-01-22",
max = Sys.Date())
}
})
## Displays Initial Map
output$casemap <- renderLeaflet(map0)
observeEvent(input$submitButton, {
if (input$typeChoice == "Raw"){
df <- selectdates(start = input$daterange[1], end = input$daterange[2])
df$Total <- df$Count_Sum
} else if (input$typeChoice == "Percentage"){
df <- selectdates(start = input$daterange[1], end = input$daterange[2])
df$Total <- df$Perc_Sum
} else {return(NULL)}
row.names(df) <- df$FIPS
dta2 <- dta
dta2$Total <- df$Total
new.colours <- colorNumeric(palette = "YlOrRd", domain = dta2$Total)
## Updates Labels
labels <- sprintf(
"<strong>%s</strong><br/>%g Cases",
dta2$County, dta2$Count
) %>% lapply(htmltools::HTML)
## Updates Leaflet Plot
###### I ASSUME THE CHANGE IS REQUIRED HERE ######
leafletProxy("casemap") %>% clearControls()
leafletProxy("casemap", data = dta2) %>%
setShapeStyle(
layerId = ~FIPS,
fillColor = ~ new.colours(dta2$Total)) %>%
addLegend(
pal = new.colours,
values = dta2$Total,
opacity = 1,
title = "Count")
})
}
## Run the application
shinyApp(ui = ui, server = server)
库(ggplot2)
图书馆(单张)
图书馆(单张)
图书馆(闪亮)
图书馆(shinycssloaders)
图书馆(DT)
##加载数据
tmp%lappy(htmltools::HTML)
##创建初始贴图
map0%
addTiles()%>%
添加多边形(
layerId=~FIPS,
fillColor=~颜色(计数),
重量=1,
不透明度=0.7,
color=“白色”,
dashArray='3',
fillOpacity=0.7
highlight=highlightOptions(
重量=5,
color=“#666”,
dashArray=“”,
fillOpacity=0.7,
bringToFront=TRUE),label=labels,labelOptions=labelOptions(
样式=列表(“font-weight”=“normal”,padding=“3px 8px”),
textsize=“15px”,
direction=“auto”))
##用户界面功能开始
用户界面,而不是调用传单代理两次,你能尝试合并成一个吗<代码>传单代理(“casemap”,data=dta2)%%>%clearControls()%%>%ect