我有一个 Shiny 的数据表。当用户选择某一行时,我想在新窗口中显示基于所选行的其他一些数据。我尝试使用 ShinyBS 包,但没有操作按钮我无法使用它,我不想包含操作按钮。我希望在选择一行时显示弹出窗口。有任何想法吗?
mymtcars = head(mtcars)
for_pop_up = 1:6
app <- shinyApp(
ui = fluidPage(
DT::dataTableOutput("mydatatable")
),
server = shinyServer(function(input, output, session) {
mycars = head(mtcars)
output$mydatatable = DT::renderDataTable(mycars, selection = 'single',
rownames = FALSE, options = list(dom = 't'))
output$popup = renderPrint({
for_pop_up[input$mydatatable_rows_selected]
})
})
)
runApp(app)
最佳答案
您可以使用observeEvent 和模态对话框,如下所示:
mymtcars = head(mtcars)
for_pop_up = 1:6
app <- shinyApp(
ui = fluidPage(
DT::dataTableOutput("mydatatable")
),
server = shinyServer(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,]
))
})
})
)
希望这可以帮助!
关于r - Shiny 的数据表 : popup data about selected row in a new window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45151436/