我正在尝试Shiny而我喜欢它.我构建了一个小应用程序,学生上传一个csv文件,然后选择一个因变量和自变量,然后R计算一个线性回归.它工作正常.我把它上传到:
http://carlosq.shinyapps.io/Regresion
[如果需要,可以使用此文件进行测试."beer"是因变量,除"id"之外的其余变量是独立的]
这是server.R:
# server.R
library(shiny)
shinyServer(function(input, output) {
filedata <- reactive({
infile <- input$file1
if (is.null(infile)){
return(NULL)
}
read.csv(infile$datapath)
})
output$dependent <- renderUI({
df <- filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
selectInput("dependent","Select ONE variable as dependent variable from:",items)
})
output$independents <- renderUI({
df <- filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
selectInput("independents","Select ONE or MANY independent variables from:",items,multiple=TRUE)
})
output$contents <- renderPrint({
input$action
isolate({
df <- filedata()
if (is.null(df)) return(NULL)
fmla <- as.formula(paste(input$dependent," ~ ",paste(input$independents,collapse="+")))
summary(lm(fmla,data=df))
}) …Run Code Online (Sandbox Code Playgroud)