Link 闪亮的两个数据表输出
Link two dataTable Outputs in Shiny
我想在不使用额外标签的情况下从另一个打开一个 table。我有以下代码使 2 tables 同时可见,但我希望第二个只有在我单击第一个后才可见。所以,我认为需要某种点击(link)来使第二个 table 可见,并且在此之前只需要显示第一个 table。
set.seed(0)
mydf <- data.frame(Type = sample(LETTERS[1:5], 30, replace = TRUE),
Amount = sample(10:200, 30, replace = TRUE),
stringsAsFactors= FALSE, check.names = FALSE)
mydf_agg <- aggregate(list(Amount=mydf$Amount),list(Type=mydf$Type),sum)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(width=3,status="primary",solidHeader=T,collapsible=T, title="Summary", DT::dataTableOutput("mytable_summary")),
box(width=3,status="primary",solidHeader=T,collapsible=T, title="More Data", DT::dataTableOutput("mytable"))
)
)
server <- function(input, output) {
output$mytable_summary <- DT::renderDataTable({ mydf_agg })
output$mytable <- DT::renderDataTable({ mydf })
}
# Run the application
shinyApp(ui = ui, server = server)
非常感谢任何帮助。
我们可以在这里使用 shinyjs
包 show
/hide
函数。
library(shiny)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
useShinyjs(),
box(width=3,status="primary",solidHeader=T,collapsible=T, title="Summary",
DT::dataTableOutput("mytable_summary")),
box(width=3,status="primary",solidHeader=T,collapsible=T, title="More Data",
DT::dataTableOutput("mytable"))
)
)
server <- function(input, output) {
rv <- reactiveValues(flag = FALSE)
output$mytable_summary <- DT::renderDataTable({mydf_agg})
output$mytable <- DT::renderDataTable({ mydf })
observeEvent(input$mytable_summary_cell_clicked, {
if(rv$flag) show('mytable')
else hide('mytable')
rv$flag <- !rv$flag
})
}
# Run the application
shinyApp(ui = ui, server = server)
我想在不使用额外标签的情况下从另一个打开一个 table。我有以下代码使 2 tables 同时可见,但我希望第二个只有在我单击第一个后才可见。所以,我认为需要某种点击(link)来使第二个 table 可见,并且在此之前只需要显示第一个 table。
set.seed(0)
mydf <- data.frame(Type = sample(LETTERS[1:5], 30, replace = TRUE),
Amount = sample(10:200, 30, replace = TRUE),
stringsAsFactors= FALSE, check.names = FALSE)
mydf_agg <- aggregate(list(Amount=mydf$Amount),list(Type=mydf$Type),sum)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(width=3,status="primary",solidHeader=T,collapsible=T, title="Summary", DT::dataTableOutput("mytable_summary")),
box(width=3,status="primary",solidHeader=T,collapsible=T, title="More Data", DT::dataTableOutput("mytable"))
)
)
server <- function(input, output) {
output$mytable_summary <- DT::renderDataTable({ mydf_agg })
output$mytable <- DT::renderDataTable({ mydf })
}
# Run the application
shinyApp(ui = ui, server = server)
非常感谢任何帮助。
我们可以在这里使用 shinyjs
包 show
/hide
函数。
library(shiny)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
useShinyjs(),
box(width=3,status="primary",solidHeader=T,collapsible=T, title="Summary",
DT::dataTableOutput("mytable_summary")),
box(width=3,status="primary",solidHeader=T,collapsible=T, title="More Data",
DT::dataTableOutput("mytable"))
)
)
server <- function(input, output) {
rv <- reactiveValues(flag = FALSE)
output$mytable_summary <- DT::renderDataTable({mydf_agg})
output$mytable <- DT::renderDataTable({ mydf })
observeEvent(input$mytable_summary_cell_clicked, {
if(rv$flag) show('mytable')
else hide('mytable')
rv$flag <- !rv$flag
})
}
# Run the application
shinyApp(ui = ui, server = server)