按输入值过滤r闪亮的boxplot

时间:2015-11-10 16:23:40

标签: r shiny

我试图从ui.r获取输入值,在本例中为filterValue,并按输入值过滤我的数据帧(mpgData)。然后我想创建另外两个变量的箱线图。

ui.r

library(shiny)
shinyUI(pageWithSidebar(

  headerPanel("Filtered Boxplot"),

  sidebarPanel(
    selectInput("filterValue", "Filter Variable:",
                list("value1" = "value1", "value2" = "value2", ..."value100" = "value100"))

    selectInput("variable", "Variable:",
        list("Tier" = "tier", 
        "Second_variable" = "second_variable"))
  ),

    mainPanel(
      h3(textOutput("caption")),
      plotOutput("mpgPlot")
    )
  ))

server.r

library(shiny)
library(datasets)

data <- read.csv("csv_file", header=TRUE, fill= TRUE, check.names = FALSE)
mpgData <- data
mpgData$tier <- factor(mpgData$tier, labels = c("A", "B", "C", "D"))

shinyServer(function(input, output) {

  newData <- reactive({
    a <- subset(mpgData, column_name %in% input$filterValue)
    a <- droplevels(a)
  return(a)
  })

  formulaText <- reactive({
    paste("column_name ~", input$variable)
  })

  output$caption <- renderText({
    formulaText()
  })

  output$mpgPlot <- renderPlot({
    boxplot(as.formula(formulaText()), 
            data = newData)
  })
})

我收到此错误:

  

as.data.frame.default(data)出错:无法强制类   &#34;&#34;反应&#34;&#34;到data.frame

我是否错过了将csv上传转换为数据帧的步骤?

0 个答案:

没有答案