想要编写一个应用程序,以使用闪亮和comparef软件包动态比较xlsx文件的不同版本。
以html格式输出比较结果时出现问题。
如何解决?可以使用htmlTable包输出html吗?
library(shiny)
library(compareDF)
library(htmlTable)
ui <- navbarPage("Compare_app",
tabPanel("Compare relults",
sidebarLayout(
sidebarPanel(
fileInput(inputId = "old_file",
label = "Chose old file",
accept = c(".xlsx")),
fileInput(inputId = "new_file",
label = "Chose new file",
accept = c(".xlsx")),
selectInput(inputId = "group_cols",
label = "Group by:",
choices = "",
selected = NULL,
multiple = TRUE)
),
mainPanel(
mainPanel(
htmlOutput(outputId = "compare_html")
)
)
)
)
)
server <- function(input, output, session) {
old_file <- reactive({
old_file_tmp <- read_excel(req(input$old_file$datapath), col_names = TRUE)
})
new_file <- reactive({
old_file_tmp <- read_excel(req(input$new_file$datapath), col_names = TRUE)
})
observeEvent(old_file(), {
updateSelectInput(session, "group_cols", choices = names(old_file()))
})
output$compare_html <- renderUI({
vec <- unlist(strsplit(input$group_cols, ","))
compare_result_tmp <- compareDF::compare_df(df_new = new_file(), df_old = old_file(), group_col = vec)
compare_html <- compare_result_tmp$html_output
})
)
# Run the application
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
这可以通过使用本机的闪亮命令轻松实现-
compare_html <- shiny::HTML(compare_result_tmp$html_output)
这应该以预期的格式提供输出