2016-10-10 8 views
0

내 반짝이는 앱을 실행할 때 오류가 발생했습니다. 오류가 ui.R에서 보이는 것처럼 보이지만 여러 번 확인한 후에도 알아 내지 못합니다. 누구 아이디어가 있습니까? 다음은 내 코드입니다 :반짝 반짝 빛나는 match.arg (위치) 오류 : 'arg'는 NULL 또는 문자 벡터 여야합니다

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 

답변

2

그것은 (그것은 당신의 오류 메시지 추적에있어) sidebarLayout에 호출합니다. 당신이 ?sidebarLayout 보면 , 그것은 4 개 인수

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

세 번째 인수는 문자열 "왼쪽"또는 "오른쪽"위치 인 것입니다 걸립니다. 세 번째 인수는 mainPanel이고 두 번째는 sidebarPanel입니다. 그것이 당신이 그 논쟁을 얻는 이유입니다.

+0

Thx! 두 번째 사이드 바 패널을 삭제 한 후에 오류가 사라졌습니다. 하지만 두 개의 사이드 바 패널을 포함하려면 어떻게해야합니까? 나는 그것들을 하나의 패널에 짜 넣는 대신에 분리하기를 원한다. – lotone

+0

그건 정말 별개의 질문입니다. (나는 반짝 반짝 빛나지 않습니다.) –

+0

고마워요! 어제 밤에 거의 동일한 코드를 사용하고 앱을 성공적으로 배포했기 때문에 사실 정말 이상합니다. 이제 그래프를 추가하고 ui.r을 변경하려고합니다. 그러면 오류가 나타납니다. 불행히도 나는 내 ui.r의 원래 버전을 저장하지 않았다. – lotone

관련 문제