1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
##########################################################################3
## experimental new(er) version of .dataFrame
## helper for rowname wrangling:
.rownamesAreUnique <- function(df) {
identical(
length(rownames(df)),
length(unique(rownames(df)))
)
}
.dataFrame3 <- function(
df, ..., summaryMessage = "", serverOptions = list(orderClasses = TRUE)
) {
rowNames <- rownames(df)
## If the rownames are unique then just use the names as idx.
## but if not, then also also append supplementary idx
if (.rownamesAreUnique(df)) {
dt <- data.frame(idx = rowNames, df)
} else {
dt <- data.frame(idx = seq_len(nrow(df)), rownames = rowNames, df)
}
## define the app
app <- list(
ui = fluidPage(
titlePanel("Select rows in the Data Table"),
sidebarLayout(
sidebarPanel(
actionButton("btnSend", "Send"),
width = 1
),
mainPanel(
DT::dataTableOutput('tbl')
)
)
),
server = function(input, output) {
output$tbl <- DT::renderDataTable(
df, server = TRUE, filter = "top",
options = serverOptions
)
if (length(summaryMessage) != 1L) {
output$summary <- renderUI({
HTML(paste0(
sprintf(
'<span class="shiny-html-output" >%s</span> ',
summaryMessage
), "<br>"
))
})
}
observe({
if (input$btnSend > 0)
isolate({
idx <- input$tbl_rows_selected
stopApp(returnValue = df[idx,])
})
})
}
)
.runApp(app, ...)
}
setMethod("display", signature(object = "data.frame"),
function(object, ...) {
.dataFrame3(df=object, ...)
}
)
|