【问题标题】:Can't display the result of a statistical test with R Shiny无法使用 R Shiny 显示统计测试的结果
【发布时间】:2021-12-17 21:27:47
【问题描述】:

我编写了一个脚本来使用 R 计算统计测试。一切正常,我得到了我的结果。
现在我想用 R Shiny 来做。目标是导入带有fileInput组件的文件,然后进行统计测试,最后显示出来。
我试图同时定义 UI 部分和服务器部分,但这不起作用。确实我有以下错误:

发生了错误。检查您的日志或联系应用作者 澄清

这是我的 R 脚本:

library("lsr")
library("shiny")

ui <- fluidPage(
  titlePanel("title panel"),
  fluidRow(
    column(3, fileInput("file", h3("File input"))
    )
  ),
  fluidRow(
  column(width = 3, textOutput("info"))
 )
)

server <- function(input, output) {
  output$info <- renderText({
  mycsv <- read.csv(input$file, header = TRUE, sep = ";") 
  mycsv <- subset(mycsv, V12=="Nutriment")
  df <- as.data.frame(t(mycsv))
  colnames(df) <- c("an1", "an2")
  df2 <- head (df,-2)
  cramer<-cramersV(df2$an1, df2$an2)
  res<-data.frame(cramer)
 })
}

shinyApp(ui = ui, server = server)

编辑:使用的数据集是一个:

0;1;10;2;3;4;5;6;7;8;9;姓名;年份 0;3;0;4;3;0;1;0;4;0;2;保守主义;2020
0;0;0;1;2;1;4;2;4;1;1;湿度;2021
0;0;0;1;2;2;3;2;2;0;0;营养;2020
0;0;0;0;2;3;4;2;2;0;0;营养;2021
0;1;0;2;4;5;2;0;1;1;0;保守主义;2021
0;0;0;0;3;3;3;2;3;2;1;湿度;2020

问题出在哪里,如何显示存储在res 变量中的结果?
任何帮助将不胜感激,谢谢。

【问题讨论】:

  • 如果没有最小的可重现示例,就无法判断,但至少 subset(mycsv, V12=="Nutriment") 看起来很奇怪(它真的拼写为 Nutriment)吗?但如果这不是问题,您真的应该提供minimal reproducible example 和确切的错误消息。
  • @dario - 感谢您的回答,编辑完成。是的,Nutriment 是我用来做子集的列的值。

标签: r shiny shiny-server


【解决方案1】:

试试这个

library("lsr")
library("shiny")

ui <- fluidPage(
  titlePanel("title panel"),
  fluidRow(
    column(3, fileInput("file", h3("File input")))
  ),
  fluidRow(
    column(width = 6, DTOutput("t1"), 
           verbatimTextOutput("info")
           )
  ) 
)

server <- function(input, output) {
  
  mycsv <- reactive({
    req(input$file)
    mycsv <- read.csv(input$file$datapath, header = TRUE, sep = ",") 
    mydf <- subset(mycsv, name=="Nutriment")
    mydf
  })
  
  output$t1 <- renderDT({
    datatable(mycsv())
  })
  
  output$info <- renderPrint({

    df <- as.data.frame(tFrame(mycsv()))
    colnames(df) <- c("an1", "an2")
    df2 <- head(df,-2)
    cramer<-cramersV(df2$an1, df2$an2)
    res<-data.frame(cramer)
    res
  })
}

shinyApp(ui = ui, server = server)

【讨论】:

    猜你喜欢
    • 2013-09-10
    • 2019-08-02
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多