r - 选择文件小部件:“FUN 中的错误:找不到对象‘类型’”
问题描述
我正在构建一个闪亮的应用程序,它允许我使用小部件“选择文件”和“选择文件”选择数据文件,以及使用库 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 种操作类型的收入条,条形颜色根据观察结果而有所不同。我希望能够选择我想要的数据并获得这个数据集的条形图。
解决方案
推荐阅读
- java - 我也可以将@Bean 注解应用于函数吗?
- angular - 每次用户单击按钮时创建整个动态表单添加到 Angular
- html - 如何在html表中的每一行的末尾给出符号
- laravel - 当请求在laravel中并行时如何使用队列
- python - Pandas 系列 apply lambda: NoneType found,但系列中只有 str 和 list
- mysql - 如何为每个用户创建nodejs不同的mysql连接
- windows - 在 Flutter for Windows 平台中实现浏览按钮
- vba - Split() 函数给出编译错误:标识符无效
- python - 如何在 tkinter 中为我的重试按钮添加功能?
- python - Python:将变量输出到现有的 Excel 工作表上