【发布时间】: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 语句,它就会运行。无论如何要返回从闪亮模块中的数据表中选择的行吗?任何帮助将不胜感激。
【问题讨论】:
-
谢谢,你的评论帮我弄明白了