我有一个闪亮的仪表盘,在下面的选项卡中。Documents
我显示前两行的 iris
数据集。
当我点击列的任何单元格时 Species
我自动转到 View
标签。
但我需要下面描述的功能。
当用户点击 setosa
第一行的单元格 Documents
在侧边栏中的标签页中,将数据化的数据进行处理。View
只显示 iris
数据集。当我点击 setosa
的第2行的单元格。Documents
在侧边栏中的标签页中,将数据化的数据进行处理。View
标签页应该只显示另一个数据框,比如说 mtcars
.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(DT)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(),
sidebar = dashboardSidebar(
DT::DTOutput("dt2")
),
body = dashboardBody(tabsetPanel(
id = "myTabsetPanel",
tabPanel("Documents",
DTOutput("dt1")),
tabPanel("Species")
)),
),
server = function(input, output, session) {
output$dt1 <- renderDT(
iris[1:2,],
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")
}
})
output$dt2<-renderDT(
if(input$myTabsetPanel=="Species"){
iris
}
else{
return(NULL)
}
)
}
)
像这样吗?
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(DT)
library(datasets)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(),
sidebar = dashboardSidebar(),
body = dashboardBody(tabsetPanel(
id = "myTabsetPanel",
tabPanel("Documents",
DT::DTOutput("dt1")),
tabPanel("Species",
DT::DTOutput("dt2"))
)),
),
server = function(input, output, session) {
output$dt1 <- renderDT(
iris[1:2,],
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")
}
})
output$dt2 <- renderDT(
if(input$dt1_cell_clicked$row == 1){
iris
}
else{
mtcars
}
)
}
)