shinydashboard框背景

时间:2018-05-16 00:02:54

标签: r shinydashboard

我无法弄清楚为什么背景颜色不能用于我的shinydashboard应用程序。每个框应该只包含要转到链接的标题,描述和按钮,但是尽管完全按照github页面(https://rstudio.github.io/shinydashboard/structure.html#boxes)示例,我的页面不显示颜色。任何有关为什么的帮助非常感谢。示例代码如下。

    {
      library('shiny')
      library('shinydashboard')
    }

    # UI

    ui<-fluidPage(
      titlePanel("Sample Code"),
      fluidRow(
        column(6,
               h1("Sample 1"),

               shinydashboard::box(title = "Google", "Description for Google", solidHeader = TRUE, background = "green",
                                   br(),
                                   shiny::actionButton(inputId='link1', label="Go To Google", 
                                                       onclick ="window.open('https://google.com', '_blank')")
               ),



               shinydashboard::box(title = "Stack Overflow", "Description for Stack Overflow", solidHeader = TRUE, background = "blue",
                                   br(),
                                   shiny::actionButton(inputId='link2', label="Go To Stack", 
                                                       onclick ="window.open('https://stackoverflow.com/', '_blank')")
               )

        )
      ))


    #SERVER
    server<-function(input,output,session)
    {
    }

    #Run the Shiny App to Display Webpage
    shinyApp(ui=ui, server=server)

1 个答案:

答案 0 :(得分:1)

您正在使用fluidPage和dashboard-elements。这种组合不起作用。你必须使ui完全适应这样的仪表板:

{
  library('shiny')
  library('shinydashboard')
}

# UI

ui<-dashboardPage(
  dashboardHeader(
    title="Sample Code"
  ),
  dashboardSidebar(),
  dashboardBody(
    column(6,
           h1("Sample 1"),

           shinydashboard::box(title = "Google", "Description for Google", solidHeader = TRUE, background = "green",width = 10,
                               br(),
                               shiny::actionButton(inputId='link1', label="Go To Google", 
                                                   onclick ="window.open('https://google.com', '_blank')")
           ),

           shinydashboard::box(title = "Stack Overflow", "Description for Stack Overflow", solidHeader = TRUE, background = "blue",width = 10,
                               br(),
                               shiny::actionButton(inputId='link2', label="Go To Stack", 
                                                   onclick ="window.open('https://stackoverflow.com/', '_blank')")
           )

    )
  ))


#SERVER
server<-function(input,output,session)
{
}

#Run the Shiny App to Display Webpage
shinyApp(ui=ui, server=server)

我还在框中添加了width = 10参数,否则它们不能很好地显示。