r - 单击 DTdatatable 中的单元格并移动到闪亮应用程序的另一个选项卡
问题描述
我在下面有闪亮的仪表板,我想知道是否可以使列的单元格Species
交互,例如,如果用户单击该列的某个单词'setosa'
,以移动到选项卡Species
。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(DT)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
),
sidebar = dashboardSidebar(),
body = dashboardBody(
tabsetPanel(
tabPanel("Documents",
DTOutput("dt1")),
tabPanel("Species")
)
),
),
server = function(input, output) {
library(readxl)
output$dt1<-renderDT(
iris,filter = "top",
options = list(
pageLength = 5
)
)
}
)
解决方案
请检查以下内容:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(DT)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(),
sidebar = dashboardSidebar(),
body = dashboardBody(tabsetPanel(
id = "myTabsetPanel",
tabPanel("Documents",
DTOutput("dt1")),
tabPanel("Species")
)),
),
server = function(input, output, session) {
output$dt1 <- renderDT(
iris,
filter = "top",
options = list(pageLength = 5),
selection = list(mode = 'single', target = 'cell')
)
observeEvent(input$dt1_cell_clicked, {
# alternative: input$dt1_cells_selected
if (req(input$dt1_cell_clicked$value) == "setosa") {
updateTabsetPanel(session, inputId = "myTabsetPanel", selected = "Species")
}
})
}
)
推荐阅读
- javascript - Odin 项目中的重复字符串
- javascript - 使用元素条件拆分数组
- sql - 将数据类型从另一列导入外键/在 SQL 中使用未定义的外键类型?
- python - 当我知道 n 的平方根的所有因数时,如何得到数 n 的所有因数?
- lyx - 在 Lyx 中将文本放在图像之后?
- javascript - 为什么 Promise.all() 返回一个空数组?
- python - 计算同一列中两点之间的时间差(ArcGIS)
- angular - 覆盖指令的 ngOnDestroy 方法
- python - 在 DRF 中过滤特定数据以进行响应
- masstransit - 如何为 MultiBus 的 ISendEndPointProvider 创建依赖注入