r - R Shiny App-数据表输出未呈现
问题描述
下面是我的闪亮应用程序的代码。最终目标是让用户上传 2 个具有相同列标题的 csv 文件,并且输出应该是 2 个 csv 文件之间不同的行。该应用程序似乎可以上传 csv 文件,但闪亮的应用程序中没有显示表格。此外,我希望最终将完整的输出表导出到 csv,但我尚未将其包含在我的代码中。
library(shiny)
library(dplyr)
library(gridExtra)
library(grid)
library(stringr)
ui <- fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose First Data File",
multiple = FALSE, accept = c("text/csv", "text/comma-separated-values, text/plain",
".csv")),
fileInput("file2", "Choose Second Data File",
multiple = FALSE, accept = c("text/csv", "text/comma-separated-values, text/plain",
".csv")),
tags$hr(),
checkboxInput("header", "Header", TRUE),
radioButtons("sep", "Separator", choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
radioButtons("quote", "Quote", choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
tags$hr(),
radioButtons("disp", "Display", choices = c(Head = "head", All = "all"), selected = "head")
),
mainPanel(
tableOutput("contents", "export")
)
)
)
options(shiny.maxRequestSize = 30*1024^2)
server <- function(input, output) {
data <- reactive({
df <- read.csv(input$file1$datapath,
header = input$header
quote = input$quote)
df2 <- read.csv(input$file2$datapath,
header = input$header
quote = input$quote)
df$COLUMNA <- str_replace_all(df$COLUMNA, "[[:punct:]]", "")
df2$COLUMNA <- str_replace_all(df2$COLUMNA, "[[:punct:]]", "")
diff_df <- anti_join(df, df2, by = c("COLUMNA", "COLUMNB", "COLUMNC"))
return(diff_df)
})
}
output$contents <- renderTable({
req(input$file1, input$file2)
if(input$disp == "head") {
head(data()$diff_df)
}
else {data()$diff_df}
})
shinyApp(ui, server)
解决方案
您是否尝试将以下代码移动到您的server
函数中?
output$contents <- renderTable({
req(input$file1, input$file2)
if(input$disp == "head") {
head(data()$diff_df)
}
else {data()$diff_df}
})
这renderTable
应该在server
功能上起作用,但似乎你把它放在了server
.
推荐阅读
- c++ - 这个#在C++的函数参数中是什么意思
- c# - 如何通过 C# 中的英特尔图形以编程方式更改屏幕亮度
- javascript - ReactJS Axios 使用 Multer 传递数据和上传图片
- java - Spring Security OAuth2 使用主机和端口将资源服务器连接到授权服务器 url
- php - Spatie/Laravel-Permissions:虚拟数据错误
- php - 如何总计数组列?
- wpf - 最大高度为容器的百分比
- java - android java的泛型类型错误
- c# - 在 WPF 中模拟 ShowDialog
- python - 如何使烧瓶应用程序成为多处理?