我有以下 Shiny-app
-
library(shiny)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
div(id = "Div1", style = "height: 100px; width: 100px; background-color: red;"),
div(id = "Div2", style = "height: 100px; width: 100px; background-color: blue;")
),
server = function(input, output) {
onclick('Div1', showModal(modalDialog(
div(id = "Div3", style = "height: 100px; width: 100px; background-color: black;", tableOutput("tab")),
)))
}
)
在这个应用中,如果我点击 Div1
那么 Modal dialog box
将会打开。然而,我想扩展这个条件,如果我点击任何一个的 Div1
或 Div2
然后同样 dialog box
会打开。
有什么方法可以实现吗?
你可以使用一个变通的方法,如 https:/github.comdaattalishinyjsissues167。
library(shiny)
library(shinyjs)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
div(id = "Div1", style = "height: 100px; width: 100px; background-color: red;"),
div(id = "Div2", style = "height: 100px; width: 100px; background-color: blue;")
),
server = function(input, output, session) {
ids <- c("Div1", "Div2")
for (id in ids) {
local({
shinyjs::onclick(id, {
showModal(modalDialog(
div(id = "Div3", style = "height: 100px; width: 100px; background-color: black;", tableOutput("tab")),
))
})
})
}
}
)