0

In the following R shiny code below, I am trying to embed two boxes aligned left and right with a selectInput widget above the left box and the entire thing appearing in a bsmodal popup when we click the Button. I am not able to get the desired result however, please help me with the tweak such that I can make it appear upon button click. Thanks

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)
Adam Shaw
  • 519
  • 9
  • 24

1 Answers1

2

This should do the job:

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

Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • way to go Sir, I am definitely accepting this one, however small request, if the below plot can be arranged to the right than below? – Adam Shaw Apr 13 '18 at 07:33