我正在使用 R 3.2.3通过RStudio版本0.99.491,在Windows 10 64bit ...我正在创建 传单 app,使用毕业的 圈标记 。我想显示不同月份以使用 selectInput() 显示数据更改,但我不知道如何将其连接到' radius =' addCirclemarker() 的参数使其动态化。我知道我只是用半径=' addCirclemarker() 的参数,但我无法判断我是否错误 selectInput() 。这是我data使用的String#[]。结果显示没有错误消息,并且当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')
))))
server.r
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)
})
})
谢谢!
答案 0 :(得分:1)
对于我的具体问题的解决方案,我使用了来自superzip应用程序的代码,对于任何制作带有标记的小册子闪亮应用程序的人来说,这似乎已经全部。 http://shiny.rstudio.com/gallery/superzip-example.html(点击获取代码按钮,它会将您发送给Github)
如果我错了,请纠正我,但是,sizeBy <- input$size
从choice参数中提取值,并且是selectInput()
函数的桥梁。 radius <- crossact[[sizeBy]]
通过创建变量selectInput()
,将data.frame对象中的重叠字符串分配给sizeBy
变量radius
。为此,map函数必须有一个observer({})
包装器,以便在选择更改时自行更新。
ui.r
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')
))))
Server.r
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)
})
})
})