【发布时间】:2020-02-01 02:48:25
【问题描述】:
我在这里有一个闪亮的应用程序示例。它使用DT 包显示可编辑数据表。
为了能够下载显示在多个页面上的所有数据,我将server=FALSE 与renderDT 一起使用。
我现在想要实现的是
-
限制用户编辑某些特定的列。 以下代码似乎不起作用。
editable = list(target = 'cell', disable = list(column = c("Sepal.Length", "Sepal.Width"))) 我想在导出到 csv 时指定一个默认文件名,例如
data.csv。这可能吗?
如果有人可以帮助我,非常感谢。非常感谢。
library(shiny)
library(DT)
library(dplyr)
# UI
ui = fluidPage(
selectInput("nrows",
"select n entries",
choices = 100:150,
selected = 100,
multiple = FALSE),
DT::dataTableOutput('tbl'),
checkboxGroupInput('datacols',
label='Select Columns:',
choices= c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
selected = c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
inline=TRUE )
)
# SERVER
server = function(input, output) {
df = reactiveValues()
observe ({
df$dat = iris %>% .[1:input$nrows, ]
})
# render DT
output$tbl = renderDT(server=FALSE, {
datatable(df$dat %>% select(one_of(input$datacols)),
editable = list(target = 'cell', disable = list(column = c("Sepal.Length", "Sepal.Width"))), #"cell",
extensions = "Buttons",
options = list(
dom = "Bfrtip", buttons = list("csv")))
})
observeEvent(input[["tbl_cell_edit"]], {
cellinfo <- input[["tbl_cell_edit"]]
df$dat <- editData(df$dat, input[["tbl_cell_edit"]])
})
}
shinyApp(ui=ui, server = server)
【问题讨论】: