我正在尝试建立一个闪亮的web应用程序,我希望在弹出窗口中显示R函数的结果图,而不是在mainPanel中。例如,对于下面的示例(来自http://shiny.rstudio.com/articles/action-buttons.html),单击"Go“按钮将在弹出窗口中显示相同的绘图。
我试着添加一些javascript,但还没有成功...有人能帮上忙吗?
提前谢谢你!
library(shiny)
ui <- fluidPage(
actionButton("go", "Go"),
numericInput("n", "n", 50),
plotOutput("plot")
)
server <- function(input, output) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
output$plot <- renderPlot({
hist(randomVals())
})
}
shinyApp(ui, server)发布于 2015-11-26 16:17:18
查看提供modal弹出窗口的shinyBS包。下面的示例显示了单击按钮时的绘图。
编辑-在模态中添加了一个下载按钮
rm(list = ls())
library(shiny)
library(shinyBS)
shinyApp(
ui =
fluidPage(
sidebarLayout(
sidebarPanel(numericInput("n", "n", 50),actionButton("go", "Go")),
mainPanel(
bsModal("modalExample", "Your plot", "go", size = "large",plotOutput("plot"),downloadButton('downloadPlot', 'Download'))
)
)
),
server =
function(input, output, session) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
plotInput <- function(){hist(randomVals())}
output$plot <- renderPlot({
hist(randomVals())
})
output$downloadPlot <- downloadHandler(
filename = "Shinyplot.png",
content = function(file) {
png(file)
plotInput()
dev.off()
})
}
)

发布于 2015-11-26 09:38:34
您可以使用conditional panel来显示/隐藏包含绘图的absolute panel,将条件设置为某个js变量,该变量由附加到按钮的函数切换。
例如:
conditionalPanel("popupActive==1",
absolutePanel(id = "popup", class = "modal",
fixed = FALSE, draggable = TRUE,
top = 200, right = "auto", left = 400,
bottom = "auto",
width = 500, height = 500,
plotOutput(#output plot stuff#)
)
)然后在js中切换popupActive的值以显示/隐藏
HTML('<head><script>popupActive = 0; function myFunction(){popupActive=!popupActive;} </script></head>'), HTML('<button id="go" type="button" class="btn btn-default action-button" onclick="myFunction()">Go</button>'),发布于 2020-04-21 23:07:19
使用原生闪亮的功能
library(shiny)
ui <- fluidPage(
actionButton("go", "Go"),
numericInput("n", "n", 50)
)
server <- function(input, output) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
output$plot <- renderPlot({
hist(randomVals())
})
observeEvent(input$go, {
showModal(modalDialog(
plotOutput("plot"),
footer = NULL,
easyClose = TRUE
))
})
}
shinyApp(ui, server)

https://stackoverflow.com/questions/33925430
复制相似问题