11

我有调查数据。我想使用 Shiny 与合作者分享我的单变量和双变量分析结果。在调查中有数值变量和因子变量。根据查看 Shiny 应用程序的人是否对单变量/双变量摘要感兴趣,并且根据他们想要总结的变量类型,我希望出现不同的输出。

具体来说,

i) 如果是单变量和数字,则显示:

  • 项目回复率:length() - sum(is.na())
  • hist()
  • summary()

ii) 如果是单变量和因子,则显示:

  • 项目响应率
  • barplot()
  • table()
  • prop.table()

iii) 如果是双变量和 numeric*numeric,则显示:

  • 项目响应率
  • 散点图:plot(x,y)
  • summary(x)
  • summary(y)
  • cor(x,y,method="spearman")

iv) 如果是双变量和因子*因子,则显示:

  • 项目响应率
  • 条形图...类似于“rCharts nvd3 multiBarChart”
  • table(x,y)
  • prop.table(x,y)
  • chisq.test(x,y)

v) 如果二元和 (factor*numeric OR numeric*factor) 则显示:

  • 项目响应率
  • 箱形图
  • 按因子变量汇总数值变量:by(numeric, factor, summary)
  • 克鲁斯卡尔瓦利斯测试kruskal.test(numeric ~ factor)

目前,我有代码可以为所有 5 个步骤生成所需的输出作为单独的应用程序。我想将它们组合成 1 Shiny 应用程序。我在概念上苦苦思索如何将mainPanel()显示设置为响应不同的输出,它将作为用户在sidebarPanel()UI 上做出的选择的函数而接收到的不同输出。

具体来说,

  • 如何更改mainPanel()UI 标题以反映不同的输出
  • 如何在概念上扩展下面的代码以包含多段输出(即,下面的代码适用于单段verbatimTextOutput(),但我不知道如何处理我想要显示的多段/类型的输出,如 (i-iv ) 上面。例如文本、表格、图表。

下面是我的 ui.R 文件代码:

library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Shiny Example"),
sidebarPanel(
wellPanel(
selectInput(inputId = "variable1",label = "Select First Variable:", 
choices = c("Binary Variable 1" = "binary1",
"Binary Variable 2" = "binary2", 
"Continuous Variable 1" = "cont1",
"Continuous Variable 2" = "cont2"),
selected = "Binary Variable 1"
)
),

wellPanel(
checkboxInput("bivariate", "Proceed to Bivariate Analysis", FALSE),
conditionalPanel(
condition="input.bivariate==true",
selectInput(inputId = "variable2", 
label = "Select Second Variable:",
choices = c("Binary Variable 1" = "binary1",
"Binary Variable 2" = "binary2", 
"Continuous Variable 1" = "cont1",
"Continuous Variable 2" = "cont2"),
selected = "Binary Variable 2"
)
)
)
),

mainPanel(
h5("Output"),
verbatimTextOutput("out")
)
))

下面是我的模拟数据和我的 server.R 文件:

binary1 <- rbinom(100,1,0.5)
binary2 <- rbinom(100,1,0.5)
cont1   <- rnorm(100)
cont2   <- rnorm(100)

dat <- as.data.frame(cbind(binary1, binary2, cont1, cont2))

dat$binary1 <- as.factor(dat$binary1)
dat$binary2 <- as.factor(dat$binary2)
dat$cont1 <- as.numeric(dat$cont1)
dat$cont2 <- as.numeric(dat$cont2)

library(shiny)
library(rCharts)

shinyServer(function(input, output) {

inputVar1 <- reactive({
parse(text=sub(" ","",paste("dat$", input$variable1)))
})

inputVar2 <- reactive({
parse(text=sub(" ","",paste("dat$", input$variable2)))
})

output$out <- renderPrint({

if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
table(eval(inputVar1()))
} else {

if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
summary(eval(inputVar1()))
} else {

if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
table(eval(inputVar1()), eval(inputVar2()))
} else {

if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
cor(eval(inputVar1()), eval(inputVar2()))
} else {

if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
by(eval(inputVar2()), eval(inputVar1()), summary)
} else { 

if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
by(eval(inputVar1()), eval(inputVar2()), summary)
}
}
}
}
}
}

})

})

您能提供的任何帮助将不胜感激。甚至只是简单地展示如何调整代码以在给定变量选择的情况下呈现两个所需的输出。以及如何调整标题以反映命名的输出片段。

在此先感谢...克里斯

4

3 回答 3

18

即使问题是很久以前的问题,我认为这种方法可能更好,不需要在服务器端添加额外的代码。

mainPanel(

  wellPanel(
    conditionalPanel(
        condition = "input.myInput == 'value'",
        ..... Your UI for this case ...........
    ),

    conditionalPanel(
        condition = "input.myInput == 'value2'",
        ..... Your UI for this case ...........
    )                 
  )
  )
于 2014-04-23T09:42:44.847 回答
5

我修改了您的 Shiny 代码(见下文),以便它执行您想要的操作。根据 Uni 与 Bivariate 分析的选择,它会切换选项卡并显示相关结果。

概括地说,这是我必须在您的代码中更改以获得所需行为的内容:

  1. 引入tabPanel以便可以对输出进行分段。
  2. 引入了一个observe响应式,以便可以在其中监视您要进行的嵌套 if-else。
  3. 我创建了多个 output$variables,以便可以在其中呈现每个选项。
  4. 对于标题,我只是h4在相应tabPanel的 s中添加了一个

Shiny App 运行截图 下面附上一个完整的工作代码。以此为起点,然后从那里开始。

用户界面

library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("Conditional Tab Switch Example"),
  sidebarPanel(
    wellPanel(
      selectInput(inputId = "variable1",label = "Select First Variable:", 
                  choices = c("Binary Variable 1 (Factor)" = "binary1",
                              "Binary Variable 2 (Factor)" = "binary2", 
                              "Continuous Variable 1 (Numeric)" = "cont1",
                              "Continuous Variable 2 (Numeric)" = "cont2"),
                  selected = "Binary Variable 1 (Factor)"
      )
    ),

    wellPanel(
      checkboxInput("bivariate", "Proceed to Bivariate Analysis", FALSE),
      conditionalPanel(
        condition="input.bivariate==true",
        selectInput(inputId = "variable2", 
                    label = "Select Second Variable:",
                    choices = c("Binary Variable 1 (Factor)" = "binary1",
                                "Binary Variable 2 (Factor)" = "binary2", 
                                "Continuous Variable 1 (Numeric)" = "cont1",
                                "Continuous Variable 2 (Numeric)" = "cont2"),
                    selected = "Binary Variable 2 (Factor)"
        )
      )
    )
  ),

    mainPanel(
      h5("Output"),
      tabsetPanel(id ="analysisTabs",
              tabPanel(title = "Univariate Numeric", value="panel_uni_numeric",
                       h4(" Univariate Numeric"),                       
                       verbatimTextOutput("uni_numeric")),
              tabPanel(title = "Univariate Factor", value="panel_uni_factor",
                       h4(" Univariate Factor"),                       
                       verbatimTextOutput("uni_factor")),
              tabPanel(title = "Bivariate Numeric-Numeric", value="panel_bi_nn",
                       h4(" Bivariate Numeric Numeric"),                       
                       verbatimTextOutput("bi_numeric1_numeric2")),
              tabPanel(title = "Bivariate Factor-Factor", value="panel_bi_ff",
                       h4(" Bivariate Factor Factor"),                       
                       verbatimTextOutput("bi_factor1_factor2")),
              tabPanel(title = "Bivariate Numeric-Factor", value="panel_bi_nf",
                       h4(" Bivariate Numeric Factor"),                       
                           verbatimTextOutput("bi_numeric1_factor2")),
              tabPanel(title = "Bivariate Factor-Numeric", value="panel_bi_fn",
                       h4(" Bivariate Factor Numeric"),                       
                       verbatimTextOutput("bi_factor1_numeric2"))

              )
        )  
  ))

服务器.R

binary1 <- rbinom(100,1,0.5)
binary2 <- rbinom(100,1,0.5)
cont1   <- rnorm(100)
cont2   <- rnorm(100)

dat <- as.data.frame(cbind(binary1, binary2, cont1, cont2))

dat$binary1 <- as.factor(dat$binary1)
dat$binary2 <- as.factor(dat$binary2)
dat$cont1 <- as.numeric(dat$cont1)
dat$cont2 <- as.numeric(dat$cont2)

library(shiny)
#library(rCharts)

shinyServer(function(input, output, session) {

  inputVar1 <- reactive({
    parse(text=sub(" ","",paste("dat$", input$variable1)))
  })

  inputVar2 <- reactive({
    parse(text=sub(" ","",paste("dat$", input$variable2)))
  })


  output$uni_factor = renderText({
    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) { 
      table(eval(inputVar1()))
    }
  })
  output$uni_numeric = renderPrint({
    if( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
      summary(eval(inputVar1()))
    }
  })
  output$bi_factor1_factor2 = renderText({
    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
        table(eval(inputVar1()), eval(inputVar2()))
     }    
  })
  output$bi_numeric1_numeric2 = renderPrint({
    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) { 
        cor(eval(inputVar1()), eval(inputVar2()))
    }
  })
  output$bi_numeric1_factor2 = renderPrint({
    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) { 
       by(eval(inputVar2()), eval(inputVar1()), summary)
    }
  })
  output$bi_factor1_numeric2 = renderPrint({
    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) { 
       by(eval(inputVar1()), eval(inputVar2()), summary)
    }
  })


  observe({  
    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
      print("uni f")
      updateTabsetPanel(session, inputId="analysisTabs", selected="panel_uni_factor")
    } 
    else if( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
      print("uni n")
      updateTabsetPanel(session, inputId="analysisTabs", selected="panel_uni_numeric")
      } 
    else if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
      print("bi f f")
      updateTabsetPanel(session, inputId="analysisTabs", selected="panel_bi_ff")
        }
    else if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
      print("bi n n")
      updateTabsetPanel(session, inputId="analysisTabs", selected="panel_bi_nn")
          } 
    else if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
      print("bi f n")
      updateTabsetPanel(session, inputId="analysisTabs", selected="panel_bi_fn")
            } 
    else if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
      print("bi n f")
      updateTabsetPanel(session, inputId="analysisTabs", selected="panel_bi_nf")
    }

  })#end observe

})

更新 根据评论,我更新了 server.R 以仅在满足渲染条件时才显示结果。具体来说,请注意output$uni_factor = renderText({类型语句后面的每个 if 语句。仍然可以单击选项卡,但它们不会显示任何结果。(Shiny 小组中有一个关于完全隐藏选项卡的讨论,但据我所知,它尚未明确实施。)

于 2013-07-30T23:59:14.893 回答
2

如上所述,我继续解决问题。我在 server.R 文件中嵌入了一系列嵌套的 if else 语句,以根据所选输入有条件地生成字幕。我利用textOutput()ui.R 文件中的函数在mainPanelUI 中显示这些标题。这工作得很好,但不确定它是否是最好的方法。想听听关于这种方法的想法吗?

至于条件输出......取决于变量和分析(单变量或双变量)的选择,我想生成最多 5 个输出。因此,我再次使用一系列嵌套的 if else 语句来生成这些输出。然后显示在 ui.R 文件中。我现在的问题与那些不需要 5 个输出(最大可能)的变量组合和分析有关。对于他们,我返回NULL对象。我的问题是 Shiny 不会为这些输出打印空白。相当闪亮返回一个灰色框和单词“NULL”。它看起来有点难看,我非常感谢有关如何将此输出简单地转换为空白的任何反馈。

我的新 ui.R 代码如下:

    library(shiny)
    shinyUI(pageWithSidebar(

headerPanel("Shiny Example"),

    sidebarPanel(

        wellPanel(

        selectInput(    inputId = "variable1",label = "Select First Variable:", 
                choices = c("Binary Variable 1" = "binary1",
                "Binary Variable 2" = "binary2", 
                "Continuous Variable 1" = "cont1",
                "Continuous Variable 2" = "cont2"),
                selected = "Binary Variable 1"
        )
        ),


        wellPanel(

            checkboxInput("bivariate", "Proceed to Bivariate Analysis", FALSE),
        conditionalPanel(
        condition="input.bivariate==true",
        selectInput(inputId = "variable2", 
        label = "Select Second Variable:",
        choices = c("Binary Variable 1" = "binary1",
        "Binary Variable 2" = "binary2", 
        "Continuous Variable 1" = "cont1",
        "Continuous Variable 2" = "cont2"),
        selected = "Binary Variable 2"
    )
    )
    )
    ),
    mainPanel(

    h5("Item Response Rate"),
    verbatimTextOutput("nitem"),

    h5(textOutput("caption2")),
    verbatimTextOutput("out2"),

    h5(textOutput("caption3")),
    verbatimTextOutput("out3"),

    h5(textOutput("caption4")),
    verbatimTextOutput("out4"),

    h5(textOutput("caption5")),
    plotOutput("out5")
    )
    ))

下面是我的 server.R 文件的代码:

    binary1 <- rbinom(100,1,0.5)
    binary2 <- rbinom(100,1,0.5)
    cont1   <- rnorm(100)
    cont2   <- rnorm(100)

    dat <- as.data.frame(cbind(binary1, binary2, cont1, cont2))

    dat$binary1 <- as.factor(dat$binary1)
    dat$binary2 <- as.factor(dat$binary2)
    dat$cont1 <- as.numeric(dat$cont1)
    dat$cont2 <- as.numeric(dat$cont2)

    library(shiny)

    shinyServer(function(input, output) {

    inputVar1 <- reactive({
    parse(text=sub(" ","",paste("dat$", input$variable1)))
    })

    inputVar2 <- reactive({
    parse(text=sub(" ","",paste("dat$", input$variable2)))
    })

    output$nitem <- renderPrint({


    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    n <- sum(table(eval(inputVar1())))
    p <- n/100
    out <- cat(paste(n,gsub(" ","",paste("(",round(as.numeric(p)*100,2),"%",")"))),"\n")
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    n <- sum(table(eval(inputVar1())))
    p <- n/100
    out <- cat(paste(n,gsub(" ","",paste("(",round(as.numeric(p)*100,2),"%",")"))),"\n")
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    n <- sum(table(eval(inputVar1()),eval(inputVar2())))
    p <- n/100
    out <- cat(paste(n,gsub(" ","",paste("(",round(as.numeric(p)*100,2),"%",")"))),"\n")
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    n <- sum(table(eval(inputVar1()),eval(inputVar2())))
    p <- n/100
    out <- cat(paste(n,gsub(" ","",paste("(",round(as.numeric(p)*100,2),"%",")"))),"\n")
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    n <- sum(table(eval(inputVar1()),eval(inputVar2())))
    p <- n/100
    out <- cat(paste(n,gsub(" ","",paste("(",round(as.numeric(p)*100,2),"%",")"))),"\n")
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    n <- sum(table(eval(inputVar1()),eval(inputVar2())))
    p <- n/100
    out <- cat(paste(n,gsub(" ","",paste("(",round(as.numeric(p)*100,2),"%",")"))),"\n")
    }
    }
    }
    }
    }
    }

    })

    output$caption2 <- renderText({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    caption2 <- "Univariate Table"
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    caption2 <- "Univariate Summary"
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    captions2 <- "Bivariate Table"
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption2 <- "Numeric Summary First Variable"
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption2 <- "Numeric Summary By Factor"
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    caption2 <- "Numeric Summary By Factor"
    }
    }
    }
    }
    }
    }

    })

    output$out2 <- renderPrint({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    table(eval(inputVar1()))
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    summary(eval(inputVar1()))
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    table(eval(inputVar1()), eval(inputVar2()))
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    summary(eval(inputVar1()))
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    by(eval(inputVar2()), eval(inputVar1()), summary)
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    by(eval(inputVar1()), eval(inputVar2()), summary)
    }
    }
    }
    }
    }
    }

    })

    output$caption3 <- renderText({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    caption3 <- "Univariate Table of Proportions"
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    caption3 <- ""
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    captions3 <- "Bivariate Table of Row Proportions"
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption3 <- "Numeric Summary Second Variable"
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption3 <- "Kruskal Wallis Test"
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    caption3 <- "Kruskal Wallis Test"
    }
    }
    }
    }
    }
    }

    })


    output$out3 <- renderPrint({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    prop.table(table(eval(inputVar1())))
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    NULL
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    prop.table(table(eval(inputVar1()), eval(inputVar2())), margin=1)
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    summary(eval(inputVar2()))
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    kruskal.test(eval(inputVar2()) ~ eval(inputVar1()))
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    kruskal.test(eval(inputVar1()) ~ eval(inputVar2()))
    }
    }
    }
    }
    }
    }

    })

    output$caption4 <- renderText({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    caption4 <- ""
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    caption4 <- ""
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    captions4 <- "Pearsons Chi-Squared Test"
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption4 <- "Spearmans Correlation Coefficient"
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption4 <- ""
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    caption4 <- ""
    }
    }
    }
    }
    }
    }

    })

    output$out4 <- renderPrint({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    NULL
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    NULL
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    chisq.test(table(eval(inputVar1()), eval(inputVar2())))
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    cor(eval(inputVar1()), eval(inputVar2()), method="spearman", use="pairwise.complete.obs")
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    NULL
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    NULL
    }
    }
    }
    }
    }
    }

    })

    output$caption5 <- renderText({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    caption5 <- "Univariate Barplot"
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    caption5 <- "Univariate Histogram"
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    captions5 <- "Bivariate Barplot"
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption5 <- "Bivariate Scatter Graph"
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    caption5 <- "Bivariate Boxplot"
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    caption5 <- "Bivariate Boxplot"
    }
    }
    }
    }
    }
    }

    })

    output$out5 <- renderPlot({

    if ( (input$bivariate==FALSE) & (is.factor(eval(inputVar1()))==TRUE) ) {
    barplot(table(eval(inputVar1())))
    } else {

    if ( (input$bivariate==FALSE) & (is.numeric(eval(inputVar1()))==TRUE) ) {
    hist(eval(inputVar1()),main="")
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    barplot(table(eval(inputVar1()), eval(inputVar2())), beside=TRUE)
    } else {

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    plot(eval(inputVar1()), eval(inputVar2()), main="")
    } else {

    if ( (input$bivariate==TRUE) & (is.factor(eval(inputVar1()))==TRUE) & (is.numeric(eval(inputVar2()))==TRUE) ) {
    boxplot(eval(inputVar2()) ~ eval(inputVar1()))
    } else { 

    if ( (input$bivariate==TRUE) & (is.numeric(eval(inputVar1()))==TRUE) & (is.factor(eval(inputVar2()))==TRUE) ) {
    boxplot(eval(inputVar1()) ~ eval(inputVar2()))
    }
    }
    }
    }
    }
    }

    })

    })

如前所述,我当前的问题是打印“NULL”输出。如果有人对如何禁止出现此输出有任何建议,我将非常感谢您的反馈。此外,我欢迎对提议的解决方案提出想法,而不是其他可行的解决方案。

于 2013-08-01T16:27:30.863 回答