我正在尝试构建一个有光泽的Web应用程序,我想在弹出窗口而不是在mainPanel中显示R函数的结果图.例如,对于以下示例(来自http://shiny.rstudio.com/articles/action-buttons.html),单击"开始"按钮将在弹出窗口中显示相同的图.
我试着添加一些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)
Run Code Online (Sandbox Code Playgroud)
Por*_*hop 13
查看shinyBS提供modal弹出窗口的包.下面的示例显示了按钮单击时的图表.
编辑 - 为模态添加了一个下载按钮
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()
})
}
)
Run Code Online (Sandbox Code Playgroud)
使用原生 Shiny 功能
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10113 次 |
| 最近记录: |