gpt4 book ai didi

r - match.arg(位置): 'arg' must be NULL or a character vector 中的 Shiny 错误

转载 作者:行者123 更新时间:2023-12-03 19:53:49 25 4
gpt4 key购买 nike

运行 Shiny 的应用程序时出现错误。该错误似乎在 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 s。这就是你得到这个论点的原因。

关于r - match.arg(位置): 'arg' must be NULL or a character vector 中的 Shiny 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39967867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com