2014-06-09 4 views
2

나는이 ANOVA Shiny 앱을 운 좋게 실행하려고 노력 중이다. 출력은 목록이어야하므로 아마도 이러한 데이터 유형을 출력하는 방법을 혼동합니다. 어떤 제안? 도움에 미리ANOVA shiny app

server.R

library(shiny) 
library(car) 

shinyServer(function(input, output) { 

    csvfile <- reactive({ 

    csvfile <- input$file1 
    if (is.null(csvfile)){return(NULL)} 
    dt <- read.csv(csvfile$datapath, header=input$header, sep=input$sep) 
    dt 

    }) 

    output$var <- renderUI({ 

    if(is.null(input$file1$datapath)){return()} 

    else list (

     radioButtons("dvar", "Please Pick The Dependent Variable", choices = names(csvfile())), 
     radioButtons("ivar", "Please Pick The Independent Variable", choices = names(csvfile())), 
     actionButton("submit", "Submit") 

    ) 
    }) 

    output$aovSummary = renderTable({ 
    if (is.null(input$file1$datapath)){return()} 

    if (input$submit > 0) { 

     if (input$type == 'type1'){ 

     isolate(anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile())) 

    } 

    if (input$type == 'type2'){ 

    isolate(Anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile()), Type = "II", test.statistic = "F")) 

     } 

     if (input$type == 'type3'){ 

     isolate({ 
      fit <- aov(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile())) 
      drop1(fit, ~ . , test = 'F') 
     }) 

     } 

    }}) 

}) 

ui.R는

library(shiny) 

shinyUI(pageWithSidebar(

    headerPanel('Analysis of Variance'), 

    sidebarPanel(

    fileInput("file1", "CSV File", accept=c("text/csv", "text/comma-separated-values,text/plain", ".csv")), 

    checkboxInput("header", "Header", TRUE), 

    radioButtons('sep', 'Separator', 
      c(Comma=',', 
       Semicolon=';', 
       Tab='\t'), 
      ','), 

    selectInput('type', 'Please select Sums of Squares type', 
      c(I = 'type1', II = 'type2', III = 'type3'), 'type1'), 

    uiOutput('var') 

), 

    mainPanel(

    h3('ANOVA Table'), 
    verbatimTextOutput('aovSummary') 

) 
)) 

감사합니다.

+0

정확히 작동하지 않는 항목은 무엇입니까? 컨트롤이 보이십니까? –

+0

@ John Paul 출력이 없으므로 null 응답이 반환되는 것 같습니다. 그 이유는 확실하지 않습니다. – sugarfacex101

답변

4

코드를 실행하려고했습니다. 서식 문제가있었습니다. 아래 코드는 나를 위해 실행됩니다. 나는 그것을 테스트 할 CSV가 없지만 그것은 당신을 위해 일할 수 있습니다.

library(shiny) 
library(car) 

runApp(
    list(
    ui = pageWithSidebar(
     headerPanel('Analysis of Variance'), 
     sidebarPanel(
     fileInput("file1", "CSV File", accept=c("text/csv", "text/comma-separated-values,text/plain", ".csv")), 
     checkboxInput("header", "Header", TRUE), 
     radioButtons('sep', 'Separator',c(Comma=',',Semicolon=';',Tab='\t'),','), 
     selectInput('type', 'Please select Sums of Squares type', 
        c(I = 'type1', II = 'type2', III = 'type3'), 'type1') 
     ,uiOutput('var') 
    ) 
     , mainPanel( 
     h3('ANOVA Table'), 
     tableOutput('aovSummary') 
    ) 
    ) 
    , server = function(input, output, session) { 
     csvfile <- reactive({ 
     csvfile <- input$file1 
     if (is.null(csvfile)){return(NULL)} 
     dt <- read.csv(csvfile$datapath, header=input$header, sep=input$sep) 
     dt 
     }) 
     output$var <- renderUI({ 
     if(is.null(input$file1$datapath)){ 
      return() 
     }else{ 
      list (radioButtons("dvar", "Please Pick The Dependent Variable", choices = names(csvfile())), 
       radioButtons("ivar", "Please Pick The Independent Variable", choices = names(csvfile())), 
       actionButton("submit", "Submit") 
     ) 
     } 
     }) 

     output$aovSummary = renderTable({ 
     if(is.null(input$file1$datapath)){return()} 
     if(input$submit > 0){ 
      if(input$type == 'type1'){ 
      return(isolate(anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile())))) 
      } 
      if(input$type == 'type2'){ 
      return(isolate(Anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile())), Type = "II", test.statistic = "F")) 
      } 
      if(input$type == 'type3'){ 
      isolate(
       fit <- aov(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile()) 
      ) 
      return(drop1(fit, ~ . , test = 'F')) 
      } 
     } 
     }) 
    }) 
) 
+0

여전히 출력을 생성하지 않습니다. 저는 바보이고 형식이없는 코드를 입력했습니다. 죄송합니다. 그래도 도와 ​​줘서 고마워. – sugarfacex101

+0

테스트 할 csv가 있습니까? – jdharrison

+0

당신이 맞았어요. 단지 verbatimTextOutput 명령은 tableOutput이어야합니다. 그래서 나는 너에게 그것을 줄 것이다. 고맙습니다. – sugarfacex101