[英]Use ConditionalPanel with DT:datatable rows selected in shiny modules
I have a problem with convert my shiny app to use Shiny Modules. 我将我的闪亮应用程序转换为使用闪亮模块时遇到问题。 In my app I have a ConditionalPanel where conditional is a js-string to DT:datatable_rows_selected.
在我的应用程序中,我有一个ConditionalPanel,其中conditional是DT:datatable_rows_selected的js字符串。 I don't understand how I need to rewrite this condition to work with ShinyModule conception.
我不明白我需要如何重写此条件才能使用ShinyModule概念。
Example: This is work correct (when select rows in table - ConditionalPanel is open): 示例:这是正确的工作(当选择表中的行时-ConditionalPanel已打开):
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
DT::dataTableOutput("testTable"),
conditionalPanel(condition = "typeof input.testTable_rows_selected !== 'undefined' && input.testTable_rows_selected.length > 0",
verbatimTextOutput("two")
)
),
server = function(input,output) {
output$testTable <- DT::renderDataTable(mtcars, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$testTable_rows_selected)
}
)
But this is not work: 但这是行不通的:
library(shiny)
library(DT)
testUI <- function(id) {
ns <- NS(id)
tagList(
DT::dataTableOutput(ns("testTable")),
conditionalPanel(condition = "typeof input.testTable_rows_selected !== 'undefined' && input.testTable_rows_selected.length > 0",
verbatimTextOutput(ns("two"))
)
)
}
test <- function(input,output,session) {
ns <- session$ns
output$testTable <- DT::renderDataTable(mtcars, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$testTable_rows_selected)
# return(reactive(input$testTable_rows_selected))
}
shinyApp(
ui = testUI("one"),
server = function(input,output) {
out <- callModule(test,"one")
}
)
Very strange, but not needed to construct new name of table like previous answer. 非常奇怪,但是不需要像以前的答案一样构造表的新名称。 The correct - set "ns" parameter to conditional panel, and don't touch js-string for condition.
正确的-将“ ns”参数设置为条件面板,并且不要触摸js-string作为条件。 This example work correct:
此示例工作正确:
library(shiny)
library(DT)
testUI <- function(id) {
ns <- NS(id)
tagList(
fluidPage(
DT::dataTableOutput(ns("one")),
conditionalPanel(
condition = "typeof input.one_rows_selected !== 'undefined' && input.one_rows_selected.length > 0",
ns=ns,
verbatimTextOutput(ns("two"))
)
)
)
}
test <- function(input,output,session)
{
output$one <- DT::renderDataTable(mtcars, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$one_rows_selected)
}
shinyApp(
ui = testUI("p"),
server = function(input,output,session) { out <- callModule(test,"p")}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.