简体   繁体   English

match.arg(position) 中的闪亮错误:“arg”必须为 NULL 或字符向量

[英]shiny Error in match.arg(position) : 'arg' must be NULL or a character vector

I went into an error when running my shiny app.运行我的闪亮应用程序时出错。 The error seems in ui.R but I have checked so many times and still can't figure it out.错误似乎在 ui.R 中,但我检查了很多次仍然无法弄清楚。 Does anyone have ideas?有没有人有想法? Here's my code:这是我的代码:

ui.R
require(shiny)
library(radarchart)
shinyUI(navbarPage("Attitude analysis",
                   tabPanel("Gender & Age Group",
                            fluidPage(
                              fluidRow(
                                column(width = 3, wellPanel(
                                  selectInput("select1", label=("Age Group"),
                                              choices=list("Age 18-24","Age 25-44","Age 45-64","Age 65+"),
                                              selected = "Age 18-24")
                                ))),
                              fluidRow(
                                column(width = 12,
                                       chartJSRadarOutput("plot1", width = "300", height = "100")
                                ),
                                column(width = 12,
                                       chartJSRadarOutput("plot2", width = "300", height = "100")
                                )
                              ))
                            ),
                   tabPanel("Attitude Comparison",
                            fluidPage(
                              sidebarLayout(

                                # Sidebar with  slider input
                                sidebarPanel(h4("Baseline"),
                                         radioButtons("select2", label=("familiarity"),
                                                      choices=list("0"=0,"1"=1 ),
                                                      selected = 0 ),
                                         radioButtons("select3", label=("favorability"),
                                                      choices=list("0"=0,"1"=1 ),
                                                      selected = 0 ),
                                         radioButtons("select4", label=("consideration"),
                                                      choices=list("0"=0,"1"=1 ),
                                                      selected = 0 )
                                ),
                                sidebarPanel(h4("Comparison"),
                                         radioButtons("select5", label=("familiarity"),
                                                      choices=list("0"=0,"1"=1 ),
                                                      selected = 0 ),
                                         radioButtons("select6", label=("favorability"),
                                                      choices=list("0"=0,"1"=1 ),
                                                      selected = 0 ),
                                         radioButtons("select7", label=("consideration"),
                                                      choices=list("0"=0,"1"=1 ),
                                                      selected = 0 )
                                  ),

                                # Show a plot of the generated distribution
                                mainPanel(
                                  plotOutput("plot3", width=900,height = 450)
                                )
                              ))
                            )
))
server.R
server <- function(input, output) {
  library(shiny)
  library(radarchart)
  library(ggplot2)
  library(reshape2)
top_version<-read.csv("top_version.csv",header = T)
top_version<-top_version[,2:26]
  output$plot1 <- renderChartJSRadar({
    ds<-subset(top_version,top_version$ageInd==input$select1)
    labs<-c('familiarity','favorability','consideration')
    scores<-list('Women'=c(nrow(ds[ds$familiarity==1 & ds$gender==2,])/nrow(ds[ds$gender==2,]),nrow(ds[ds$favorability==1 & ds$gender==2,])/nrow(ds[ds$gender==2,]),nrow(ds[ds$consideration==1 & ds$gender==2,])/nrow(ds[ds$gender==2,])),
                   'Men'=c(nrow(ds[ds$familiarity==1 & ds$gender==1,])/nrow(ds[ds$gender==1,]),nrow(ds[ds$favorability==1 & ds$gender==1,])/nrow(ds[ds$gender==1,]),nrow(ds[ds$consideration==1 & ds$gender==1,])/nrow(ds[ds$gender==1,])))
    chartJSRadar(scores=scores, labs=labs,showToolTipLabel = T)
  })
  output$plot2 <- renderChartJSRadar({
    labs<-c('familiarity','favorability','consideration')
    scores2<-list("Age 18-24"=c(nrow(top_version[top_version$familiarity==1 & top_version$ageInd=="Age 18-24",])/nrow(top_version[top_version$ageInd=="Age 18-24",]),nrow(top_version[top_version$favorability==1 & top_version$ageInd=="Age 18-24",])/nrow(top_version[top_version$ageInd=="Age 18-24",]),nrow(top_version[top_version$consideration==1 & top_version$ageInd=="Age 18-24",])/nrow(top_version[top_version$ageInd=="Age 18-24",])),
                  "Age 25-44"=c(nrow(top_version[top_version$familiarity==1 & top_version$ageInd=="Age 25-44",])/nrow(top_version[top_version$ageInd=="Age 25-44",]),nrow(top_version[top_version$favorability==1 & top_version$ageInd=="Age 25-44",])/nrow(top_version[top_version$ageInd=="Age 25-44",]),nrow(top_version[top_version$consideration==1 & top_version$ageInd=="Age 25-44",])/nrow(top_version[top_version$ageInd=="Age 25-44",])),
                  "Age 45-64"=c(nrow(top_version[top_version$familiarity==1 & top_version$ageInd=="Age 45-64",])/nrow(top_version[top_version$ageInd=="Age 45-64",]),nrow(top_version[top_version$favorability==1 & top_version$ageInd=="Age 45-64",])/nrow(top_version[top_version$ageInd=="Age 45-64",]),nrow(top_version[top_version$consideration==1 & top_version$ageInd=="Age 45-64",])/nrow(top_version[top_version$ageInd=="Age 45-64",])),
                  "Age 65+"=c(nrow(top_version[top_version$familiarity==1 & top_version$ageInd=="Age 65+",])/nrow(top_version[top_version$ageInd=="Age 65+",]),nrow(top_version[top_version$favorability==1 & top_version$ageInd=="Age 65+",])/nrow(top_version[top_version$ageInd=="Age 65+",]),nrow(top_version[top_version$consideration==1 & top_version$ageInd=="Age 65+",])/nrow(top_version[top_version$ageInd=="Age 65+",])))
    chartJSRadar(scores=scores2, labs=labs,showToolTipLabel = T)
  })
  output$plot3 <- renderPlot({
    com_1<-subset(top_version,familiarity==as.integer(input$select2) & favorability==as.integer(input$select3) & consideration==as.integer(input$select4))
    com_2<-subset(top_version,familiarity==as.integer(input$select5) & favorability==as.integer(input$select6) & consideration==as.integer(input$select7))
    de_1<-rep(nrow(com_1),19)
    sum_0<-apply(com_1[,1:19],2,sum)
    portion_0<-sum_0/de_1
    de_2<-rep(nrow(com_2),19)
    sum_1<-apply(com_2[,1:19],2,sum)
    portion_1<-sum_1/de_2
    sum_overall<-apply(top_version[,1:19],2,sum)
    portion_overall<-sum_overall/nrow(top_version)
    df_0<-data.frame(i=names(top_version)[1:19],overall=portion_overall,baseline=portion_0,comparison=portion_1)
    df<-melt(df_0,id="i")
    ggplot(df, aes(x=i,y=value,colour=variable,group=variable))+
      geom_line()+
      theme(axis.text.x = element_text(angle = 90, hjust = 1))
  })
}

and the error message is:错误信息是:

Listening on http://127.0.0.1:5884 Warning: Error in match.arg: 'arg' must be NULL or a character vector Stack trace (innermost first):
    54: match.arg
    53: sidebarLayout
    52: tag
    51: tags$div
    50: div
    49: tagList
    48: attachDependencies
    47: bootstrapPage
    46: fluidPage
    45: tag
    44: tags$div
    43: div
    42: tabPanel
    41: navbarPage
    40: shinyUI
     1: runApp Error in match.arg(position) : 'arg' must be NULL or a character vector

It's in your call to sidebarLayout (it's in your error message trace).它在您对sidebarLayout的调用中(在您的错误消息跟踪中)。 If you look at ?sidebarLayout , it takes 4 arguments如果你看?sidebarLayout ,它需要 4 个参数

function (sidebarPanel, mainPanel, position = c("left", "right"), 
    fluid = TRUE) 
{
    position <- match.arg(position)
    ...

The third argument is a string "left" or "right" being the position.第三个参数是一个字符串“left”或“right”作为位置。 Your third argument seems to be a mainPanel and you are passing in two sidebarPanel s.您的第三个参数似乎是一个mainPanel并且您传入了两个sidebarPanel That's why you are getting that argument.这就是为什么你会得到这个论点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行应用程序时出现闪亮错误:match.arg(position) 中的错误:&#39;arg&#39; 必须为 NULL 或字符向量 - Shiny Error when running App: Error in match.arg(position) : 'arg' must be NULL or a character vector Shiny 应用程序中的“match.arg(position) 错误:‘arg’必须为 NULL 或字符向量” - "Error in match.arg(position) : 'arg' must be NULL or a character vector" in Shiny app 警告:match.arg中的错误:&#39;arg&#39;必须为NULL或字符向量 - Warning: Error in match.arg: 'arg' must be NULL or a character vector match.arg(regions) 中的错误:“arg”必须为 NULL 或字符向量 - Error in match.arg(regions) : 'arg' must be NULL or a character vector match.arg(opt_crit)中的错误:“ arg”必须为NULL或字符向量 - Error in match.arg(opt_crit) : 'arg' must be NULL or a character vector match.arg(p.adjust.method)中的错误:“ arg”必须为NULL或字符向量 - Error in match.arg(p.adjust.method) : 'arg' must be NULL or a character vector 尝试运行以下代码中的插补函数时,“match.arg(what) 中的错误:&#39;arg&#39; 必须为 NULL 或字符向量” - "Error in match.arg(what) : 'arg' must be NULL or a character vector" when trying to run the impute function in the below code match.arg(mvnTest)中的错误:“ arg”的长度必须为1 - Error in match.arg(mvnTest) : 'arg' must be of length 1 &#39;arg&#39;必须为NULL或字符向量 - 'arg' must be NULL or a character vector 对多个 arguments 使用 match.arg 时出错 - Error in using match.arg for multiple arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM