【发布时间】:2021-11-05 14:12:05
【问题描述】:
下面的代码分为两部分,用于编辑{shiny}中的excel文件,带有优秀的{dataEditr}包
- 第一步是在新的excel中写入并点击按钮保存
- 第二部分,显示用于验证更改的模式对话框
但是当我验证或不验证更改时,单击保存按钮时我无法再打开模式对话框。
另外,当我在模式对话框中只显示文本或表格时,一切正常。
library(shinydashboard)
library(daff)
library(dplyr)
library(DataEditR)
df1 = iris %>% slice(1:10) %>% select(-Species)
df2 = iris %>% slice(1:12)
# Define UI
ui = shinyUI(
fluidPage(
fluidRow(
box(
title = "First data",
status = "success",
width = 6,
solidHeader = TRUE,
collapsible = TRUE,
dataEditUI(id = "old_data")
),
box(
title = "New data",
status = "primary",
width = 6,
solidHeader = TRUE,
collapsible = TRUE,
dataEditUI(id = "new_data"),
br(),
actionButton("save", "Save!")
)
)
)
)
# Define server
server = shinyServer(function(input, output, session) {
data_old = dataEditServer(
"old_data",
data = df1,
col_readonly = names(df1),
col_names = FALSE,
col_options = TRUE,
row_edit = FALSE
)
data_new = dataEditServer(
"new_data",
data = df2,
col_names = FALSE,
col_options = TRUE,
row_edit = FALSE
)
diff_data = reactive({
daff::render_diff(
daff::diff_data(
data_old(),
data_new()
), view = FALSE
)
})
output$compare_df = renderUI({
HTML(
diff_data()
)
})
observeEvent(
input$save, {
showModal(
modalDialog(
span(
"Check modification before validation!",
style = "color: red; font-size: 130%;"
),
br(),
br(),
uiOutput("compare_df"),
footer = tagList(
modalButton("Cancel"),
actionButton("ok", "OK")
),
easyClose = TRUE,
size = "l"
)
)
}
)
observeEvent(
input$ok, {
print(data_new())
removeModal()
}
)
})
shinyApp(ui, server)
【问题讨论】: