【问题标题】:DataTable row selection inside shiny module闪亮模块内的DataTable行选择
【发布时间】:2016-10-18 04:05:10
【问题描述】:

我正在尝试采用这个基本工作的闪亮应用程序并将其模块化。这有效:

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 语句,它就会运行。无论如何要返回从闪亮模块中的数据表中选择的行吗?任何帮助将不胜感激。

【问题讨论】:

  • 谢谢,你的评论帮我弄明白了

标签: r shiny dt


【解决方案1】:

需要

return(reactive(input$testTable_rows_selected))

【讨论】:

    猜你喜欢
    • 2021-07-17
    • 1970-01-01
    • 2020-01-18
    • 2020-09-30
    • 2017-12-09
    • 2019-10-25
    • 2021-05-27
    • 2016-03-16
    • 2021-09-30
    相关资源
    最近更新 更多