我有以下Shiny Application:
library(shiny)
library(shinyjs)
library(shinydashboard)
UI <- fluidPage(
actionButton("create_popup1", "Create a text popup"),
actionButton("create_popup2", "Create a graph popup")
)
Server <- function(input, output){
observeEvent(input$create_popup1, {
showModal(modalDialog(
title = "test", "this is a test"
))
})
observeEvent(input$create_popup2, {
showModal(modalDialog(
p <- ggplot(mtcars, aes(x = mpg, x= disp)) + geom_point()
))
})
}
shinyApp(ui = UI, server = Server)
当你第一个按钮工作时(并弹出一个文本)。然而第二个给出了一个erorr。关于我应该改变什么以便将图形作为弹出窗口的任何想法?
答案 0 :(得分:0)
这样的事情应该有效:
library(shiny)
library(ggplot2)
library(shinyjs)
library(shinydashboard)
UI <- fluidPage(
actionButton("create_popup1", "Create a text popup"),
actionButton("create_popup2", "Create a graph popup")
)
Server <- function(input, output){
observeEvent(input$create_popup1, {
showModal(modalDialog(
title = "test", "this is a test"
))
})
observeEvent(input$create_popup2, {
showModal(modalDialog(
plotOutput("plot")
))
})
output$plot <- renderPlot({
p <- ggplot(mtcars, aes(x = mpg, y= disp)) + geom_point()
p
})
}
shinyApp(ui = UI, server = Server)