R Shiny : Conditional panel based on row selected in datatable

标签 r shiny

我是 Shiny 的新手。我想根据我在数据表中选择的行获得一个新面板。到目前为止,我已经添加了以下代码,但它似乎不起作用。您必须设置什么条件才能显示新面板并删除之前的面板?

library(shiny)

ui <- fluidPage(

conditionalPanel(
condition <- "is. null(input.dt_rows_selected) == TRUE",
DT::dataTableOutput(outputId = "dt")
),
  conditionalPanel(
condition <- "is. null(input.dt_rows_selected) == FALSE" ,
h3("Plots based on the selected row ")
)
)


server <- function(input, output){

output$dt <- DT::renderDataTable(
mtcars, server = FALSE, selection = 'single'
)
}


shinyApp(ui =ui, server = server)

最佳答案

您需要检查两个选项:

1) 输入存在

2)输入>0

喜欢:

conditionalPanel(
    condition ="typeof input.dt_rows_selected  === 'undefined' || input.dt_rows_selected.length <= 0",
    DT::dataTableOutput(outputId = "dt"))
  ,
  conditionalPanel(
    condition = "typeof input.dt_rows_selected  !== 'undefined' && input.dt_rows_selected.length > 0" ,
    h3("Plots based on the selected row ")
  )

隐藏选择行DT并显示文本后

关于R Shiny : Conditional panel based on row selected in datatable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37659214/

相关文章:

删除 Shiny 数据表excel输出中标题上方的 "title"行?

r - 因子分层抽样

r - 使用聚类分配矩阵为数据分配聚类标签

r - Shiny 的 slider 限制释放鼠标左键的 react

R 传单 - 在已打开弹出窗口的 map 上添加新标记

r - R 中 Shiny : How to set an input value to NULL after clicking on a button?

r - 使用 Data.table 的笛卡尔滚动连接

r - 在 dplyr 管道中组合 ifelse 语句变异和序列

r - 更改矩阵/数据框中的行顺序

r - 有没有办法在 Shiny 链接中打开用户的小插图?