r - 用户上传文件的统计测试
问题描述
我目前正在尝试开发一个可以对用户上传的任何文件进行统计测试的应用程序。问题是我经常在尝试进行测试时遇到问题,并且出现许多“错误”消息。例如,在这里我无法进行 t 检验。请您在我的代码中查找错误,因为我自己似乎无法找到它们。此外,如果您有任何其他代码建议可能类似于我正在尝试创建的应用程序,我很乐意看到它们以获得一些灵感并更好地了解 Shiny 的工作原理。这是我的代码的开头,非常感谢您的关注。
library(ggplot2)
library(desctable)
ui <- fluidPage(
tabPanel(
"Upload File",
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File', min=0 , max=1000 , value=500
accept=c('.csv')),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
choices = c(Comma=',', Semicolon=';', Tab='\t'),
selected = ','),
selectInput('xcol', 'X Variable', "", selected = NULL),
selectInput('ycol', 'Y Variable', "", selected = NULL),
selectInput("method", "Select t test type",
c("One-sample t test",
"Independent two-sample t test"
),
),
mainPanel(
plotOutput('MyPlot'),
tableOutput("table"),
verbatimTextOutput("summary")
)
)
)
)
server <- function(input, output, session)
{
output$table<- renderDataTable(input$file1)
myfiles <- reactive({
req(input$file1$datapath, file.exists(input$file1$datapath))
read.csv(input$file1$datapath)
})
output$summary<-renderPrint(myfiles%>%desctable(stars=list((“N” =length,
“Moyenne”= is.normal~mean,
“Médiane”=median,
“MAD”=mad))
observeEvent(myfiles(), {
req(myfiles())
nms <- colnames(myfiles())
updateSelectInput(
session,
inputId = 'xcol',
label = 'X Variable',
choices = nms, selected = nms[1]
)
updateSelectInput(
session,
inputId = 'ycol',
label = 'Y Variable',
choices = nms, selected = nms[1]
)
})
output$table <- renderTable({
if(is.null(dff())){return ()}
if(input$method == "One-sample t test"){
t.test(myfiles[input$xcol], mu = as.numeric(input$mu))
else if (input$method == "Independent two-sample t test"){
t.test(input$xcol ~ input$ycol, data = myfiles)}
output$MyPlot <- renderPlot({
req(myfiles(), input$xcol, input$ycol)
ggplot(data = myfiles(), mapping = aes_string(input$xcol, input$ycol)) +
geom_point() +theme_dark()
})}
shinyApp(ui , server)```
解决方案
推荐阅读
- javascript - 从 p:selectedCheckbox javascript 获取值复选框
- python - 计算字符串在特定列中出现的次数
- java - OptaPlanner 7.21.0 无法从 jar 文件执行 - 目录 dataDir 错误
- python - 将 Flask 配置导入非 Flask 脚本的最佳方法是什么?
- javascript - 在 Angular 6 和 Rxjs 6 中取消挂起的 HTTP 请求并再次触发 fromEvent
- javascript - 使用动态类列表动态检测图像的替代文本
- amazon-web-services - 使用 aws 进行多区域主动复制
- javascript - 光滑的滑块创建意外的行
- php - 在 laravel 的 gmail 中找不到图片
- sql - 使用带有多个条件的 REGEXP_LIKE 来匹配模式