在不使用box()的情况下,在闪亮的Navbar页面中并排拟合2个图形

时间:2019-08-08 04:27:46

标签: r shiny shinydashboard

我有一个应用程序,希望在同一行上绘制图形和数据表。我正在使用navbarPage。由于某些原因,column()函数无法正常工作,当我将宽度设置为50%时,它们不会自动彼此并排移动。

当我使用box()时,我得到了想要的输出,但是我不想要一个盒子,宁愿在地块之间没有空格。

library(shinythemes)
library(shiny)
library(DT)

ui = navbarPage("ETF Investor", theme = shinytheme("cerulean"),
              tabPanel("ETF's",
                       plotOutput("hey", width = "50%"),
                           dataTableOutput("hi", width = "50%")





                       ),
              tabPanel("Screener"),
              tabPanel("Market Conditions"),
              tabPanel("Portfolio Builder"),
              tabPanel("Jordan's Portfolio"),
              tabPanel("Documentation")

    )



server <- function(input, output) {

    output$hey = renderPlot({
        hist(rnorm(100))
    })

    output$hi = renderDataTable({
        data.frame(a = rnorm(100), b = rnorm(100))
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

这是我当前的输出 enter image description here

这是半期望的输出,每个框的宽度都设置为6。

enter image description here

1 个答案:

答案 0 :(得分:1)

通过将两列都放在fluidRow中并从各个输出对象中删除width=50%,可以得到所需的行为。下面给出一个可行的示例,希望对您有所帮助!


enter image description here


library(shinythemes)
library(shiny)
library(DT)

ui = navbarPage("ETF Investor", theme = shinytheme("cerulean"),
                tabPanel("ETF's",
                         fluidRow(
                                  column(width=6,
                                         plotOutput("hey")
                                  ),
                                  column(width=6,
                                         dataTableOutput("hi")
                                  )
                         )

                ),
                tabPanel("Screener"),
                tabPanel("Market Conditions"),
                tabPanel("Portfolio Builder"),
                tabPanel("Jordan's Portfolio"),
                tabPanel("Documentation")
)

server <- function(input, output) {

  output$hey = renderPlot({
    hist(rnorm(100))
  })

  output$hi = renderDataTable({
    data.frame(a = rnorm(100), b = rnorm(100))
  })
}

# Run the application 
shinyApp(ui = ui, server = server)