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. 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
See Question&Answers more detail:
os