Search code examples
rshinyshinydashboard

Iframe not working correctly in my Shiny App


I want the embedded website to show on the right of the sidebar menu, but the embedded website is showing within the sidebar menu. When the user presses control chart under Cell Culture, the embedded website should show clearly to the right. Here is an image of my issue dashboard]1

How can I fix this error? Here is my code:

    library(shiny)
library(shinydashboard)


ui <- 
    dashboardPage(skin="black",
                  dashboardHeader(title = "CPV Dashboard ", titleWidth = 450),
                  dashboardSidebar(
                      sidebarMenu(
                          menuItem("Tab 1", tabName = "tab 1", icon = icon("medicine"),
                                   menuItem("Cell Culture",
                                            menuItem("Control Chart",                     mainPanel(fluidRow(
                                                htmlOutput("frame")))))))


                      ),
                  
                  dashboardBody())

server = function(input, output, session){
    observe({ 
        
        test <<- paste0("https://google.com") #sample url
    })
    output$frame <- renderUI({
        input$Member
        my_test <- tags$iframe(src=test, height=800, width=800)
        print(my_test)
        my_test
    })
}
shinyApp(ui, server)

Solution

  • I think you need the dashBoardBody inside the dashboardPage.

    As far as I can see your current code isn't doing that.

    library(shiny)
    library(shinydashboard)
    
    
    ui <-
      dashboardPage(
        skin = "black",
        dashboardHeader(title = "CPV Dashboard ", titleWidth = 450),
        dashboardSidebar(sidebarMenu(
          menuItem(
            "Tab 1",
            tabName = "tab 1",
            icon = icon("medicine"),
            menuItem("Cell Culture",
                     menuItem("Control Chart"))
          )
        )),
        
        dashboardBody(mainPanel(fluidRow(htmlOutput("frame"))
      ),
    
    ))
    
    server = function(input, output, session) {
      observe({
        test <<- paste0("https://google.com") #sample url
      })
      output$frame <- renderUI({
        input$Member
        my_test <- tags$iframe(src = test,
                               height = 800,
                               width = 800)
        print(my_test)
        my_test
      })
    }
    shinyApp(ui, server)