r - 主数据表中的另一个数据表
问题描述
当用户单击该行时,是否有办法获取数据表。基本上,当用户单击任何行时,该特定行的最后 4 列应以模式显示(以数据表格式)
library(shiny)
ui <- fluidPage(
DT::dataTableOutput("mydatatable")
)
server <- function(input, output, session) {
mycars = head(mtcars)
output$mydatatable = DT::renderDataTable(mycars, selection = 'single',
rownames = FALSE, options = list(dom = 't'))
observeEvent(input$mydatatable_rows_selected,
{
showModal(modalDialog(
title = "You have selected a row!",
mycars[input$mydatatable_rows_selected,]
))
})
}
shinyApp(ui, server)
解决方案
你可以renderDataTable
在里面使用modalDialog
。
library(shiny)
library(DT)
ui <- fluidPage(
DT::dataTableOutput("mydatatable")
)
server <- function(input, output, session) {
mycars = head(mtcars)
output$mydatatable = DT::renderDataTable(mycars, selection = 'single',
rownames = FALSE, options = list(dom = 't'))
observeEvent(input$mydatatable_rows_selected,
{
showModal(modalDialog(
title = "You have selected a row!",
DT::renderDataTable({
DT::datatable(mycars[input$mydatatable_rows_selected, (ncol(mycars) - 3):ncol(mycars)])
})
))
})
}
shinyApp(ui, server)
推荐阅读
- css - 为什么 height:auto 不适用于此图像?
- css - 向一个元素添加无限平移和旋转(以不同速度)动画
- ios - 标题化 UITableViewHeader 标签
- python - 如何在张量流中张量的某些索引处插入某些值?
- python - 如何获得完整的数字列表(而不仅仅是最后一行)?
- xamarin - 导航后 iOS 模拟器未使用全屏显示我的控件
- javascript - 如何创建响应式视频 (HTML5) 背景?
- vb.net - 获取字符串文件中每一行的第二项的最简单方法是什么
- python - 将 OCR 从每个图像中检索到的文本写入与每个图像对应的单独文本文件
- powershell - Azure DevOps 获取当前用户 ObjectId