闪亮模块内的 DataTable 行选择
DataTable row selection inside shiny module
我正在尝试采用这个基本的工作闪亮应用程序并将其模块化。这有效:
shinyApp(
ui = fluidPage(
DT::dataTableOutput("testTable"),
verbatimTextOutput("two")
),
server = function(input,output) {
output$testTable <- DT::renderDataTable({
mtcars
}, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$testTable_rows_selected)
}
)
我想让这个模块适用于任何 data.frame
# UI element of module for displaying datatable
testUI <- function(id) {
ns <- NS(id)
DT::dataTableOutput(ns("testTable"))
}
# server element of module that takes a dataframe
# creates all the server elements and returns
# the rows selected
test <- function(input,output,session,data) {
ns <- session$ns
output$testTable <- DT::renderDataTable({
data()
}, selection=list(mode="multiple",target="row"))
return(input[[ns("testTable_rows_selected")]])
}
shinyApp(
ui = fluidPage(
testUI("one"),
verbatimTextOutput("two")
),
server = function(input,output) {
out <- callModule(test,"one",reactive(mtcars))
output$two <- renderPrint(out())
}
)
这让我出错,说我正在尝试在反应性环境之外使用反应性。如果我删除 return 语句,它就会运行。无论如何 return 从闪亮模块中的数据表中选择的行?任何帮助将不胜感激。
需要
return(reactive(input$testTable_rows_selected))
我正在尝试采用这个基本的工作闪亮应用程序并将其模块化。这有效:
shinyApp(
ui = fluidPage(
DT::dataTableOutput("testTable"),
verbatimTextOutput("two")
),
server = function(input,output) {
output$testTable <- DT::renderDataTable({
mtcars
}, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$testTable_rows_selected)
}
)
我想让这个模块适用于任何 data.frame
# UI element of module for displaying datatable
testUI <- function(id) {
ns <- NS(id)
DT::dataTableOutput(ns("testTable"))
}
# server element of module that takes a dataframe
# creates all the server elements and returns
# the rows selected
test <- function(input,output,session,data) {
ns <- session$ns
output$testTable <- DT::renderDataTable({
data()
}, selection=list(mode="multiple",target="row"))
return(input[[ns("testTable_rows_selected")]])
}
shinyApp(
ui = fluidPage(
testUI("one"),
verbatimTextOutput("two")
),
server = function(input,output) {
out <- callModule(test,"one",reactive(mtcars))
output$two <- renderPrint(out())
}
)
这让我出错,说我正在尝试在反应性环境之外使用反应性。如果我删除 return 语句,它就会运行。无论如何 return 从闪亮模块中的数据表中选择的行?任何帮助将不胜感激。
需要
return(reactive(input$testTable_rows_selected))