Choosefile小部件:“ FUN中发生错误:找不到对象'Type'”

时间:2019-05-15 12:21:12

标签: r shiny widget reactive

我正在构建一个闪亮的应用程序,它将允许我使用小部件“选择文件”和“选择文件”来选择数据文件,以及使用库ggplot2的geom_bar对象绘制条形图。该图由一个表示每种操作类型(“类型”)的收入(“收入”)的条形图组成,并且每种类型的条形颜色都不同。 当我运行该应用程序时,出现以下错误:FUN中的错误:找不到对象“类型”。

我已经通过aes_string更改了aes,但是它没有任何改变。我还尝试在geom_bar对象中添加Inherit.aes = FALSE。我确保将使用的数据另存为数据框。

library(shiny)
library(ggplot2)
library(dplyr)

#user interface
ui <- fluidPage(
  headerPanel(title = "Shiny File Upload"),
  sidebarLayout(
    sidebarPanel(
      fileInput(inputId = "file",
                label = "Upload the file",
                multiple = TRUE),
      checkboxInput(inputId = "header", label = "Header"),
      radioButtons("sep","Seperator", choices = c(Comma=",", Period = ".", Semicolon = ";")),


      # Select variable for y-axis
      selectInput(inputId = "y", 
                  label = "Revenue:",
                  choices = "Revenue",
                  selected = ""),

      # Select variable for x-axis
      selectInput(inputId = "x", 
                  label = "X-axis:",
                  choices = "Type",
                  selected = ""),

      # Select variable for color
      selectInput(inputId = "z", 
                  label = "Color by:",
                  choices = "Type",
                  selected = "")
    ), 
    # Outputs
    mainPanel(
      uiOutput("input_file"),
      plotOutput(outputId = "Barplot")
    )
  )
)

# Define server function required to create the scatterplot
server <- function(input, output) {


  #Dispays the content of the input$file dataframe
  output$filedf <- renderTable({
  if(is.null(input$file)){return()}
   input$file
  })
  output$filedf2 <- renderTable({
    if(is.null(input$file)){return()}
    input$file$datapath
  })
  #Side bar select input widget coming through render UI()
  output$selectfile <- renderUI({
    if(is.null(input$file)){return()}
    list(hr(),
         helpText("Select the files for which you need to see data and summary stats"),
         selectInput("Select", "Select", choices=input$file$name)
         )
  })


      # Create the scatterplot object the plotOutput function is expecting

  output$Barplot <- renderPlot({
    ggplot(data = input$file, aes_string(x = input$x , y = input$y, fill = input$x)) + geom_bar( stat ="identity") + coord_flip()

  })  
}

shinyApp(ui = ui, server = server)

我希望有一种针对14种类型的操作的带有收益栏的条形图,条形的颜色取决于观察结果。 我希望能够选择所需的数据并获得该数据集的条形图。

0 个答案:

没有答案