制作多个R闪亮小部件会出现在弹出窗口中

时间:2018-04-13 07:14:07

标签: r shiny shinydashboard shinybs

在下面的R闪亮代码中,我试图在左框上方嵌入两个左右对齐的框,当我们点击Button时,整个东西出现在bsmodal弹出窗口中。然而,我无法获得所需的结果,请帮我调整一下,这样我就可以在点击按钮时显示它。感谢

library(DT)
library(shiny)
library(shinyBS)

ui <- basicPage(
h2("The mtcars data"),
column(5,offset = 5,actionButton("CR1_S1", "Button")),
mainPanel(
bsModal("modalExample", "Your Table", "CR1_S1", size = 
"large",uiOutput("mytable"))))
server <- function(input, output) {
output$mytable <- renderUI({
selectInput("variable", "Variable:",
            c("Cylinders" = "cyl",
              "Transmission" = "am",
              "Gears" = "gear"))
box(
  title = "Title 1", width = NULL, solidHeader = TRUE, status = "primary",
  plot(iris$Sepal.Length))
box(
  title = "Title 2", width = NULL, solidHeader = TRUE, status = "primary",
  plot(iris$Petal.length))})
}
shinyApp(ui, server)

1 个答案:

答案 0 :(得分:1)

这应该做的工作:

library(DT)
library(shiny)
library(shinyBS)
library(shinydashboard)

ui <- basicPage(
  h2("The mtcars data"),
  column(5,offset = 5,actionButton("CR1_S1", "Button")),
  mainPanel(
    bsModal("modalExample", "Your Table", "CR1_S1", size = "large",uiOutput("mytable"))))

server <- function(input, output,session) {

  output$plot1 <- renderPlot({
    plot(iris$Sepal.Length)
  })

  output$plot2 <- renderPlot({
    plot(iris$Petal.Length)
  })

  output$mytable <- renderUI({
    tagList(
      selectInput("variable", "Variable:",c("Cylinders" = "cyl","Transmission" = "am","Gears" = "gear")),
      column(6,
      box(
        title = "Title 1", width = NULL, solidHeader = TRUE, status = "primary",
        plotOutput("plot1"))),
      column(6,box(
        title = "Title 2", width = NULL, solidHeader = TRUE, status = "primary",
        plotOutput("plot2")))
    )
  })
}
shinyApp(ui, server)

enter image description here

相关问题