Виджет Choosefile: «Ошибка в FUN: объект« Тип »не найден» - PullRequest
0 голосов
/ 15 мая 2019

Я создаю блестящее приложение, которое позволило бы мне выбрать файл данных с помощью виджета «выбрать файл» и «выбрать файл», а также построить гистограмму с помощью объекта geom_bar из библиотеки ggplot2. График состоит из гистограммы, представляющей доход («Доход») по типу операции («Тип»), и имеет разные цвета столбца для каждого типа. Когда я запускаю приложение, я получаю следующую ошибку: Ошибка в FUN: объект «Тип» не найден.

Я изменил aes на aes_string, но это ничего не меняет. Я также пытался добавить в поле 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 типов операций у вас будет гистограмма с гистограммой выручки, цвет которой будет отличаться в зависимости от наблюдения. Я ожидаю, что смогу выбрать нужные данные и получить гистограмму для этого набора данных.

...