select 在 r shiny 传单应用程序中输入的问题

problems with select input in r shiny leaflet app

我正在使用 R 3.2.3 到 RStudio 版本 0.99.491,在 Windows 10 64 位...我正在创建一个 leaflet shiny 应用程序,使用毕业 circlemarkers。我想使用 selectInput() 显示不同的月份来显示数据的变化,但我不知道如何将它连接到 'radius =' addCirclemarker() 的参数使其动态化。我知道我只是用 addCirclemarker() 的 'radius =' 参数来弥补,但我不知道我是否有selectInput()也错了。这是我正在使用的 data。结果显示没有错误消息,并且当半径参数被赋予单列分配时地图工作,即静态地图。

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)
})
})

谢谢!

为了解决我的具体问题,我使用了 superzip 应用程序中的代码,对于任何制作带有标记的传单闪亮应用程序的人来说,这似乎都有了。
http://shiny.rstudio.com/gallery/superzip-example.html(点击“获取代码”按钮,它会将您转到 Github)

如果我错了请纠正我,但是,sizeBy <- input$size 从 choice 参数中提取值,并且是通往 selectInput() 函数的桥梁。 radius <- crossact[[sizeBy]] 通过使变量 radius 将 data.frame 对象中的重叠字符串分配给 selectInput() 变量 sizeBy。为此,地图函数必须有一个 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)
    })
  })
})