【发布时间】:2019-02-18 08:30:15
【问题描述】:
我创建了一个看起来像这样的闪亮应用:
## Library
library(shiny)
library(shinydashboardPlus)
library(shinyjs)
library(DT)
data <- cbind(
seq(from = 1, to = 30, by = 1),
sample(seq(from = 100, to = 300, by = 10), size = 30, replace = TRUE),
sample(seq(from = 1, to = 100, by = 9), size = 30, replace = TRUE),
sample(seq(from = 50, to = 60, by = 2), size = 30, replace = TRUE),
sample(seq(from = 100, to = 130, by = 1), size = 30, replace = TRUE)
) %>%
as.data.frame()
names(data) <- c("Colimn 1", "Colimn 2", "Colimn 3", "Colimn 4", "Colimn 5")
## UI
ui <- dashboardPagePlus(
dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "angle-left"
),
dashboardSidebar(),
dashboardBody(dataTableOutput("dataTable")),
rightSidebar()
)
## Server
server <- function(input, output) {
output$dataTable <- renderDataTable({
datatable(data,
rownames= FALSE,
selection = "single",
escape = FALSE,
## Get the name of the row on click
callback = JS("table.on('click.dt', 'tr',
function() {
Shiny.onInputChange('rows', table.rows(this).data().toArray());
});")
)
})
observeEvent(!is.null(input$rows),
{
????
})
}
shinyApp(ui, server)
我想要的是当用户点击数据表行时,右侧边栏会展开,其中包含有关该行的更多详细信息。
一旦用户点击数据表的任何一行,侧边栏应该打开,如果用户点击任何其他行,它应该保持打开状态。只有当顶部的按钮(已经存在)被按下以折叠它时,它才应该折叠。
我尝试在shinyjs::removeClass 周围玩,但我没能成功。
【问题讨论】: