" match.arg(位置)出错:' arg'必须为NULL或字符向量"在闪亮的应用程序

时间:2017-10-31 08:19:44

标签: r shiny

我在一个app.R文件中开发了一个Shiny应用程序(见下文)。我在match.arg(位置)得到"错误:' arg'必须为NULL或字符向量"错误,但不明白为什么?我已经看过以前关于这个问题的线索,它们似乎都与应用程序元素的放置问题有关(例如复制sidebarPanel等),但我无法告诉他们我是什么样的。做错了。我一直在开发这个应用程序,并且以前的迭代应用程序至少已经出现,两个selectInput正在运行。任何建议都非常感激。对于我不熟练的编码和布局表示抱歉,因为我一直在尝试遵循格式化说明,但这只会让它看起来更糟糕。考虑完全放弃,因为我花了几个小时而且绝对无处可去。

伊恩

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#

library(shiny)
library(shinydashboard) 
library(fingertipsR)
library(ggplot2)
library(viridis)
library(plotly)

#Import QOF indicators
setwd("/Users/ianbowns/Documents/R/ShinyFT")
dat <- readRDS("data")
my.df <- as.data.frame(dat)
#Defines year and age category choices
yearchoices <- unique(as.character(my.df$Timeperiod))
indicator <- unique(as.character(my.df$IndicatorName))
# Define UI for application that draws boxplot
ui <- fluidPage(

 # Application title
 titlePanel("FingerTips QOF Prevalences"),

 # Input for year and ages 
 sidebarLayout(
  sidebarPanel(
    selectInput(inputId = "year",
            label = "Choose a year:",
            choices = yearchoices,
            selected = "2015/16"),
    selectInput(inputId = "indicator",
            label = "Choose ages:",
            choices = indicators,
            selected = "All ages")),
  actionButton("goButton", "Refresh graph"),
  # Show a plot of the generated distribution
  mainPanel(
     plotlyOutput("bPlot")
  )
))


# Define server logic required to draw a histogram
server <- function(input, output) {

    inds <- my.df[which(IndicatorID == "input$indicator" & Sex == "Persons" 
          & Timeperiod == "input$year" & ParentCode != "E92000001"),]
# draw the boxplot
#                   input$goButton
        output$bPlot <- renderPlotly({
               plot_ly(data = inds, y = ~Value, color = inds$ParentName, 
type = "box", colors = viridis_pal(alpha = 1, begin = 0, end = 1, direction 
= -1, option = "D")(3), boxpoints = "all", jitter = 0.3, 
pointpos = -1.8) %>% 
               layout(title = "Dementia", titlefont = list(family = 
"Helvetica", size = 16), yaxis = list(title = "Prevalence (%)", titlefont = 
list(family = "Helvetica", size = 12)))})
}
# Run the application
shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:0)

由于你还没有提供任何数据,我会推测它不起作用,因为你没有将你的数据包装成reactive表达式。试试下面的server

# Define server logic required to draw a histogram
server <- function(input, output, session) {

  inds <- reactive({
    my.df[which(IndicatorID %in% input$indicator & Sex == "Persons" 
                & Timeperiod %in% input$year & ParentCode != "E92000001"),]
  })

  # draw the boxplot
  #                   input$goButton
  output$bPlot <- renderPlotly({
    plot_ly(data = inds(), y = ~Value, color = inds()$ParentName, 
            type = "box", colors = viridis_pal(alpha = 1, begin = 0, end = 1, direction 
                                               = -1, option = "D")(3), boxpoints = "all", jitter = 0.3, 
            pointpos = -1.8) %>% 
      layout(title = "Dementia", titlefont = list(family = 
                                                    "Helvetica", size = 16), yaxis = list(title = "Prevalence (%)", titlefont = 
                                                                                            list(family = "Helvetica", size = 12)))})
}
# Run the application
shinyApp(ui = ui, server = server)