【发布时间】:2018-01-21 12:26:06
【问题描述】:
我有以下闪亮的应用程序:
library(ggplot2)
library(Cairo) # For nicer ggplot2 output when deployed on Linux
mtcars2 <- mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "am", "gear")]
ui <- fluidPage(
fluidRow(
column(width = 4,
plotOutput("plot1", height = 300,
# Equivalent to: click = clickOpts(id = "plot_click")
click = "plot1_click",
brush = brushOpts(
id = "plot1_brush"
)
)
)
),
fluidRow(
column(width = 6
),
column(width = 6,
actionButton("show", "Show points"),
verbatimTextOutput("brush_info")
)
)
)
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(mtcars2, aes(wt, mpg)) + geom_point()
})
observeEvent(input$show, {
showModal(modalDialog(
title = "Important message",
"This is an important message!",
easyClose = TRUE
))
})
output$click_info <- renderPrint({
# Because it's a ggplot2, we don't need to supply xvar or yvar; if this
# were a base graphics plot, we'd need those.
nearPoints(mtcars2, input$plot1_click, addDist = TRUE)
})
output$brush_info <- renderPrint({
brushedPoints(mtcars2, input$plot1_brush)
})
}
shinyApp(ui, server)
现在这张表显示了我在图表上选择的点。这可行,但是我想在您选择某些内容后立即使用该数据自动创建一个弹出窗口。因此,我现在使用“显示点”按钮具有的功能,但随后输入 brushedPoints(mtcars2, input$plot1_brush)
对我如何使其工作有任何想法吗?
【问题讨论】:
标签: r ggplot2 shiny modal-dialog