本文介绍了match.arg(Position)中的闪亮错误:';arg';必须为空或字符矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在运行闪亮的应用程序时出错。错误似乎在ui.r中,但我检查了这么多次,仍然找不出来。有谁有主意吗?以下是我的代码:
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))
})
}
,错误消息为:
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
推荐答案
它在您对sidebarLayout
的调用中(它在您的错误消息跟踪中)。如果您查看?sidebarLayout
,它需要4个参数
function (sidebarPanel, mainPanel, position = c("left", "right"),
fluid = TRUE)
{
position <- match.arg(position)
...
第三个参数是作为位置的字符串"Left"或"Right"。您的第三个参数似乎是mainPanel
,并且您传入了两个sidebarPanel
。这就是您获得该参数的原因。
这篇关于match.arg(Position)中的闪亮错误:';arg';必须为空或字符矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!