【发布时间】:2022-01-19 07:59:36
【问题描述】:
我有两个共享密钥的表。第一个表始终显示在 UI 中。我希望用户能够单击表中的链接,然后显示一个模态对话框,该对话框是根据单击的链接过滤的第二个表。
具体示例:将mtcars 显示为表格,并带有gear 列的可点击链接。当单击一个时,例如4,会出现一个模式对话框,显示所有具有 4 个齿轮的汽车。如果点击3,您将获得所有具有 3 个齿轮的汽车。
似乎无论如何都没有使用shiny::actionLink() 传递参数,这是我假设我想用于表格链接的参数。我意识到下面的示例没有正确创建链接,但不知道第二步是如何工作的(作用于链接),我只是留下了一些伪代码作为示例。
library(shiny)
library(tidyverse)
ui <- fluidPage(
# Application title
titlePanel("mtcars"),
mainPanel(
tableOutput("table")
)
)
server <- function(input, output) {
output$table <- renderTable({
mtcars %>%
mutate(gear = actionLink("gearinput", label = gear)) #I realize this does not work, just leaving here as pseudo code.
})
observeEvent(input$gearinput, {
showModal(modalDialog(
title = "Gear filter",
mtcars %>% filter(gear == input$gearinput)), #I can't figure out how to actually get the value based on the link clicked
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: