require(shiny)
setwd("C://Users//Harshad//Desktop//Equiskill - BA")
cars <- read.table(file = "cars.csv", sep = ",", header = TRUE, quote="")
cars <- cars[,2:7]
ui <- fluidPage(
"Simple Linear Regression Modelling",
sidebarPanel(width = 2,
selectInput(inputId = "d_var",
label = "Select dependent variable:",
choices = c(names(cars))),
selectInput(inputId = "ind_var",
label = "Select independent variable:",
choices = c(names(cars)))
)
,
tableOutput("summary")
)
server <- function(input,output) {
model <- reactive (lm(input$d_var ~ input$ind_var, data=cars))
output$summary <- renderDataTable(
{ summary(model) }
)
}
shinyApp(ui <- ui, server <- server)
我收到错误&#34;类型&#39;关闭&#39;不是子集表格&#34;在R中执行代码时,请帮助。
我收到错误&#34;类型&#39;关闭&#39;不是子集表格&#34;在R中执行代码时,请帮助。
答案 0 :(得分:0)
这样的事情可以解决问题
require(shiny)
setwd("C://Users//Harshad//Desktop//Equiskill - BA")
cars <- read.table(file = "cars.csv", sep = ",", header = TRUE, quote="")
cars <- cars[,2:7]
ui <- fluidPage(
"Simple Linear Regression Modelling",
sidebarPanel(width = 2,
selectInput(inputId = "d_var",label = "Select dependent variable:",choices = c(names(cars))),
selectInput(inputId = "ind_var",label = "Select independent variable:",choices = c(names(cars)))
),verbatimTextOutput("summary")
)
server <- function(input,output) {
model <- reactive({
lm(cars[,names(cars) %in% input$d_var] ~ cars[,names(cars) %in% input$ind_var])
})
output$summary <- renderPrint({summary(model())})
}
shinyApp(ui <- ui, server <- server)