如何解决闪亮的sliderInput错误?

时间:2019-12-13 12:16:05

标签: r shiny leaflet

我尝试了Victorp的解决方案,其中使用seq选择要过滤的月份范围。

这里创建了一个月的月份

choices_month <- seq.Date(from = as.Date("1/1/19"), by = "month", length.out = 36)

这是滑块输入

sliderInput(inputId = "month",
                             label = h4("Month"),
                             width = "100%",
                             values = choices_month[1:12],
                             from = choices_month[1], 
                             to = choices_month[12],
                             grid = FALSE),

这里是过滤器

filter(LOCATION.EFFECTIVE.DATE == input$month[1])

我得到的错误代码是> sliderInput(inputId =“ month”,label = h4(“ Month”),width =“ 100%”,的错误:未使用的参数(值= c(2,10),从= choices_month [1]到= choices_month [12],网格= FALSE)

有人可以指出我为什么会这样吗?


library(shiny)
library(shinythemes)
library(DT)
library(plotly)
library(leaflet)
library(dplyr)
library(tidyverse)
library(leaflet.extras)

#Load dataset
peo <- read.csv("https://raw.githubusercontent.com/cwong79/DATA608/master/PEO1.csv")

#Create NAICS class type based on first 2 numeric
peo$NAICSClassCode <- as.numeric(substr(peo$NAICS, start = 1, stop = 2))

type <- c("Agriculture, Forestry, Fishing and Hunting", 
          "Mining", 
          "Utilities", 
          "Construction", 
          "Manufacturing", 
          "Wholesale Trade", 
          "Retail Trade",
          "Transportation and Warehousing", 
          "Information", 
          "Finance and Insurance", 
          "Real Estate Rental and Leasing", 
          "Professional, Scientific, and Technical Services", 
          "Management of Companies and Enterprises", 
          "Administrative and Support and Waste Management and Remediation Services", 
          "Educational Services", 
          "Health Care and Social Assistance", 
          "Arts, Entertainment, and Recreation", 
          "Accommodation and Food Services", 
          "Other Services (except Public Administration)", 
          "Public Administration")
naicsdata <- data.frame(type)
peo$NAICS_TYPE <- cut(peo$NAICSClassCode, c(1, 11, 21, 22, 23, 34, 42, 46, 50, 51, 52, 53, 54, 55, 57, 61, 63, 71, 73, 82, Inf), type)

#Unknown NAICS class
peo$NAICS_TYPE <- as.character(peo$NAICS_TYPE)
peo$NAICS_TYPE[is.na(peo$NAICS_TYPE)] <- "Unknown"

#Convert to date format
peo$LOCATION.EFFECTIVE.DATE <- as.Date(peo$LOCATION.EFFECTIVE.DATE, "%m/%d/%y")
peo$RenewalMonth <- format(peo$LOCATION.EFFECTIVE.DATE, "%m")
choices_month <- seq.Date(from = as.Date("1/1/19"), by = "month", length.out = 36)

#Determining how to sort PEO groups
peo %>% group_by(peo$NAMED.INSURED) %>% summarize(count=n())
peo %>% group_by(peo$NAICS_TYPE) %>% summarize(count=n())

#Creating a group called Tier 1
tier1 <- c("ADP TOTAL SOURCE INC", "A 1 HR A DIVISION OF OASIS OUTSOURCING INC", "COADVANTAGE CORP", "INSPERITY INC", "OASIS ACQUISITION INC", "OASIS ACQUISITION INC A PAYCHEX CO", "OASIS DHR LLC", "OASIS OUTSOURCING CONTRACT II INC", "OASIS OUTSOURCING INC", "PAYCHEX BUSINESS SOLUTIONS LLC", "PAYCHEX HR OUTSOURCING LLC", "TRINET GROUP INC", "TRINET HR II HOLDINGS INC", "TRINET HR IV LLC")

#Creating a group called Tier 2
tier2 <- c("ALLY HR LLC DBA MATRIXONESOURCE", "ALPHASTAFF GROUP INC", "CHOICE EMPLOYER SOLUTIONS INC", "CORNERSTONE CAPITAL GROUP INC", "DECISION HR", "FLORIDA RESOURCE MANAGEMENT LLC", "FRANKCRUM 2 INC", "IMPACT STAFF LEASING LLC", "JUSTWORKS EMPLOYMENT GROUP LLC", "KYMBERLY GROUP PAYROLL SOLUTIONS INC", "OCMI III INC DBA PEOPAYGO", "REGIS GROUP HOLDINGS INC", "SOUTH EAST PERSONNEL LEASING INC", "STAFFLINK OUTSOURCING INC", "THE S2 HR GROUP LLC", "TLR OF BONITA INC", "WORKFORCE BUSINESS SERVICES INC")

#Partitioning the groups
peo$Tier <- with(peo, ifelse(NAMED.INSURED %in% tier1, "1", 
                      ifelse(NAMED.INSURED %in% tier2, "2", "3")))


set.seed(305)
peo$HealthRating <- sample(1:5, replace = T)
peo$WCRating <- sample(1:5, replace = T)
peo$Strategy <- sample(1:5, replace = T)
peo$Cost <- sample(1:5, replace = T)
peo$Support <- sample(1:5, replace = T)


#Set up ui
ui <- fluidPage(theme = shinytheme("flatly"),    
                titlePanel("PEO Choices"),
                sidebarPanel(h5("", width=1),
                 checkboxGroupInput(inputId = "TierFlag",
                                    label = h4("Tier"), 
                                    choices = setNames(object = c("1", "2", "3"),
                                                       nm = c("1", "2", "3")),
                                    selected = c("1", "2", "3")), 
                 selectInput(inputId = "PeoType",
                             label = h4("Peo"),
                             choices = sort(unique(peo$NAMED.INSURED)),
                             multiple = TRUE),
                 sliderInput(inputId = "month",
                             label = h4("Month"),
                             width = "100%",
                             values = choices_month[1:12],
                             from = choices_month[1], 
                             to = choices_month[12],
                             grid = FALSE),
                 position="right"),

    #App mainPanel content and styles
          mainPanel(
                    tabsetPanel(id = 'dataset',
                                tabPanel("Map", fluidRow(leafletOutput(outputId = "map"))),
                                tabPanel("PEO Database", DT::dataTableOutput("mytable1"))
                                )
                    )
                )


#Set up server
server <- function(input, output){

#Set colors manually
pal <- colorFactor(
  palette = c('#1f78b4', '#b2df8a', '#feb24c'),
  domain = peo$Tier
)

output$mytable1 <- DT::renderDataTable({
                                        DT::datatable(peo, 
                                                      extensions = c('Buttons', 'FixedColumns', 'Scroller'),
                                                      options = list(
                                                                     dom = 'Bfrtip',
                                                                     buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                                                                     orderClasses = TRUE,
                                                                     dom = 't',
                                                                     deferRender = TRUE,
                                                                     scrollX = TRUE,
                                                                     scrollY = 300,
                                                                     fixedColumns = TRUE,
                                                                     scroller = TRUE
                                                                     ) 
                                                      )
                                       })


#Build leaflet map
map <- leaflet() %>%
  addFullscreenControl() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  setView(-80.121, 26.194, zoom = 9) %>%
  addProviderTiles("MapBox", 
                     options = providerTileOptions(id = "mapbox.dark", noWrap = FALSE, 
                                                   accessToken = 'pk.eyJ1IjoiY3dvbmc3OSIsImEiOiJjazNkNW4wOTQwa3pjM2Jva3JwZHB0OXFmIn0.h-12OxqTpTI0Pj7Wk7HJnQ')) %>%
  addCircles(lng = peo$Longitude, lat = peo$Latitude,
             popup = paste("Company Name:", peo$EMPLOYER, "<br>",
                           "PEO Type:", peo$NAMED.INSURED, "<br>",
                           "Industry:", peo$NAICS_TYPE, "<br>"),
             weight = 2, opacity = 0.5, radius = 5,
             color = pal(peo$Tier),     
             group = "myMarkers") %>%
  addLegend('bottomright',
            title = "Tiers",
            pal = pal,
            values = peo$Tier,
            opacity = 1) %>%
  addControlGPS(options = gpsOptions(position = "topright", activate = TRUE, 
                                               autoCenter = TRUE, maxZoom = 10, 
                                               setView = TRUE))
  activateGPS(map)

#Filter data
  datFilt <- reactive({
    PeoSearch <- paste0(input$TierFlag, collapse='|')
    peo[grepl(PeoSearch, peo$Tier) | 
              peo$NAMED.INSURED %in% input$PeoType & 
              filter(LOCATION.EFFECTIVE.DATE == input$month[1]),
       ]
  })

#Create an observation based on reactive server   
observe({
    tryCatch({
      if(nrow(datFilt())==0) {showNotification("Nothing selected", type='warning')
        leafletProxy("map") %>% clearShapes()
        } else{ 
        leafletProxy("map", data=datFilt()) %>%
          clearShapes() %>%
          clearControls() %>%
          addCircles(lng = datFilt()$Longitude, lat = datFilt()$Latitude,
                     popup = paste("Company Name:", datFilt()$EMPLOYER, "<br>",
                                   "PEO Type:", datFilt()$NAMED.INSURED, "<br>",
                                   "Industry:", datFilt()$NAICS_TYPE, "<br>"),
                     weight = 2, opacity = 0.5, radius = 5,
                     color = pal(datFilt()$Tier)) %>%
          addLegend('bottomright',
                    title = "Tiers",
                    pal = pal,
                    values = peo$Tier,
                    opacity = 1)
      }}, 
      error= function(e){
        showNotification(paste0(e), type='err')
      })

   })

  output$map <- renderLeaflet(map)
}

#Run app
shinyApp(ui = ui, server = server)


1 个答案:

答案 0 :(得分:1)

根据功能: https://shiny.rstudio.com/reference/shiny/0.14/sliderInput.html

sliderInput(inputId,label,min,max,value,step = NULL,round = FALSE,format = NULL,locale = NULL,ticks = TRUE,animate = FALSE,width = NULL,sep =“, “,pre = NULL,post = NULL,timeFormat = NULL,时区= NULL,dragRange = TRUE)

所以,我认为您不知道“值”是“值”,“从”是“最小”,“到”是“最大”还是“网格”。

希望它有用。

相关问题