我正在Windows 10 64bit上通过RStudio 0.99.491版使用R 3.2.3 ...我正在使用渐变的圆形标记创建一个传单闪亮的应用程序。我想显示不同的月份以使用selectInput()来显示数据的变化,但是我不知道如何将其连接到addCirclemarker()的'radius ='参数以使其动态。我知道我只是用addCirclemarker()的'radius ='参数来弥补,但是我也无法确定我是否也有selectInput()错误。这是我正在使用的数据。结果显示没有错误消息,并且在向radius参数指定了单列分配(即静态贴图)时,贴图起作用了。
ui.r:
library(shiny)
library(leaflet)
shinyUI(fluidPage(
titlePanel("CAT Rider Count Map"),
sidebarLayout(
sidebarPanel(
selectInput("var", label = "1. Select the Month",
choices = c("April" = 3, "May" = 4, "June" = 5),
selected = 4)),
mainPanel(leafletOutput('crossact.map')
))))
服务器
library(shiny)
library(googlesheets)
library(leaflet)
gs_auth()
ttt <- gs_auth()
saveRDS(ttt, "ttt.rds")
gs_auth(token = ttt)
gs_auth(token = "ttt.rds")
crossact <- gs_title("crossact")
crossact <- crossact%>% gs_read_csv()
shinyServer(
function(input, output, session){
colm <- reactive({
as.numeric(input$var)
})
output$crossact.map <- renderLeaflet({
##################################################################
#RADIUS SECTION
##################################################################
crossact.map <- leaflet(crossact) %>%
addTiles('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png')
crossact.map%>% setView(-71.43381, 42.48649, zoom = 17)
crossact.map %>% ***addCircleMarkers(~lng, ~lat, popup=~crossact$name, weight =1,
radius=~(crossact[,colm()]),
color="#ffa500", stroke = TRUE, fillOpacity = 0.6)
})
})
谢谢!
为了解决我的特定问题,我使用了superzip应用程序中的代码,对于使用标记制作传单有光泽的应用程序的任何人来说,这似乎都具备了。
http://shiny.rstudio.com/gallery/superzip-example.html(点击“获取代码”按钮,它将把您发送到Github)
如果我错了,请纠正我,但是,请sizeBy <- input$size
从choice参数中提取值,这是selectInput()
函数的桥梁。radius <- crossact[[sizeBy]]
受让人的重叠从data.frame对象到字符串selectInput()
变量sizeBy
通过使变量radius
。为此,map函数必须具有observer({})
包装器,以使其在选择更改时自动更新。
用户界面
library(shiny)
library(leaflet)
#this is the assignment of columns to the choices argument in selectinput()
vars <- c(
"April" = "April",
"May" = "May",
"June" = "June")
shinyUI(fluidPage(
h5("Integrating Leaflet With Shiny"),
titlePanel("CAT Rider Count Map"),
sidebarLayout(
sidebarPanel(
selectInput("size", "Size", vars, selected = "April")),
mainPanel(leafletOutput('crossact.map')
))))
服务器
library(shiny)
library(googlesheets)
library(leaflet)
#google authorization, token storage, file acquisition and assignment
gs_auth()
ttt <- gs_auth()
saveRDS(ttt, "ttt.rds")
gs_auth(token = ttt)
gs_auth(token = "ttt.rds")
crossact <- gs_title("crossact")
crossact <- crossact%>% gs_read_csv()
shinyServer(
function(input, output, session){
####observer is used to maintain the circle size.
observe({
#####this connects selectInput and assigns the radius value
sizeBy <- input$size
radius <- crossact[[sizeBy]]
output$crossact.map <- renderLeaflet({
crossact.map <- leaflet(crossact) %>%
addTiles('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png')
crossact.map%>% setView(-71.43381, 42.48649, zoom = 17)
crossact.map %>% addCircleMarkers(~lng, ~lat, popup=~crossact$name, weight = 1,radius = radius,
color="#ffa500", stroke = TRUE, fillOpacity = 0.6)
})
})
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句