我正试图为mtcars数据集的每个X变量与y创建一个动态图。基本上,我的y变量是"vs";列,其余的是我的X变量然而,当我尝试运行应用程序时,我会遇到以下错误。有什么想法吗?
Warning: Error in xy.coords: 'x' and 'y' lengths differ
library(shiny)
library(shinydashboard)
data("mtcars")
y <- mtcars$vs
X <- mtcars[ , !(names(mtcars) %in% "vs")]
header_app <- dashboardHeader()
sidebar_app <- dashboardSidebar()
body_app <- dashboardBody(
fluidRow(
box(
selectInput("filter", "Correlation", choices = names(X)),
plotOutput("plot1", height = "250")
) #box
) #Fluid Row
)
ui <- dashboardPage(header = header_app, sidebar = sidebar_app, body = body_app)
server <- function(input,output){
output$plot1 <- renderPlot({plot(input$filter,y)})
}
shinyApp(ui,server)
您必须从mtcars
:中提取所选列
library(shiny)
library(shinydashboard)
data("mtcars")
y <- mtcars$vs
X <- mtcars[ , !(names(mtcars) %in% "vs")]
header_app <- dashboardHeader()
sidebar_app <- dashboardSidebar()
body_app <- dashboardBody(
fluidRow(
box(
selectInput("filter", "Correlation", choices = names(X)),
plotOutput("plot1", height = "250")
) #box
) #Fluid Row
)
ui <- dashboardPage(header = header_app, sidebar = sidebar_app, body = body_app)
server <- function(input,output){
output$plot1 <- renderPlot({plot(mtcars[, input$filter],y)})
}
shinyApp(ui,server)