2

我正在尝试创建一个闪亮的仪表板(R 3.1.0 / shiny 0.12.0 / shinydashboard 0.5.0)。我已成功创建布局,并决定在仪表板侧边栏中使用多个选项卡。

侧边栏由多个选项卡组成,每个选项卡显示一组特定的图到目前为止我所做的简单屏幕截图

我正在尝试为这些图添加一个下载按钮,但我必须将它添加到标题中(以便所有选项卡都可以使用它)。我知道“messageItem”选项,但无法使用它。

有人可以帮忙吗。任何您认为可以的替代方法都是最受欢迎的。

提前致谢

[更新 - 为 UI.R 添加代码] :-

library(shinydashboard)
library(htmlwidgets)
library(rpivotTable)
library(leaflet)
library(ggplot2)
library(rCharts)
library(shiny)
library(data.table)
library(reshape)
library(dplyr)
dashboardPage(
  dashboardHeader(title="MSR Reports",
                  dropdownMenu(type = "task",
                               messageItem(
                                 from = "Download",
                                 message = "Reports",
                                 icon = icon("gear")
                               ),
                               messageItem(
                                 "Download",
                                 message = "TEST",
                                 icon = icon("life-ring"),
                                 href= "http://www.google.com"
                               )
                  )

    ),

  dashboardSidebar(
    sidebarMenu(
               menuItem("SRequests", tabName = "SRequests", icon = icon("dashboard")),
               menuItem("CRequests", tabName = "CRequests", icon = icon("th")),
               menuItem("IN", tabName = "IN", icon = icon("file-word-o")),
               menuItem("IN-Map",tabName="IN-Map",icon=icon("file-word-o"))
    )),

  dashboardBody(
                tags$head(tags$style(HTML('
                 .skin-blue.main-header .logo
                  {
                  background-color: #3c8dbc;
                  }
                 .skin-blue .main-header .logo:hover
                  {
                 background-color: #3c8dbc;
                  }'))
                 ),
                tags$head(tags$style(
                type = 'text/css',
                '#test{ overflow-x: scroll; }')),

                  tabItems(
                    tabItem(tabName = "SRequests",
                            fluidRow
                                  (
                                   h2("Dashboard",align = "center"),
                                   h3(" "),
                                   h3( " " ),
                                   tabItem(tabName = "SRequests",
                                    column(
                                         div(id="test",rpivotTableOutput('PivotTable',height=520)),width=12
                                          )
                                  )
                                  )),
                    tabItem(tabName = "CRequests",
                             fluidRow(
                                      h2("Volume by BA,align = "center"),
                                      h3(" "),
                                      h3(" "),
                                      column(
                                            dataTableOutput("CRequests") , width=10
                                           )
                                     )
                          ),
                    tabItem(tabName = "IN",
                             fluidRow(
                                      h2("INDashboard",align = "center"),
                                      h3(" "),
                                      h3(" "),
                                      column(
                                            width=4, showOutput("chart2", "highcharts")
                                            ),
                                      column(
                                            width=4, showOutput("chart3", "highcharts")
                                            ),
                                      column(
                                            width=4, showOutput("chart4", "highcharts")
                                            )

                                    )
                           ),
                    tabItem(tabName = "IN-Map",
                           h2("IN Locations"),
                             fluidRow(
                                      leafletOutput("mymap"),
                                      actionButton("recalc", "New points")
                                     )

                           )

                      )
               )
)
4

1 回答 1

0

这是同时下载所有绘图的另一种方法。您可以创建一个下载处理程序按钮,该按钮将同时以 pdf/ppt 格式下载所有图。示例代码如下:

output$downloadReport <- downloadHandler(

    filename = "You report.pdf",
    content = function(file) {
      pdf(file)

      ## If you have displayed some Datatables in any of your tabs
      pushViewport(viewport(layout = grid.layout(3, 2, heights = unit(c(0.5, 5, 5), "null")))) 
      sample<- sampledatatable() ## Function which you have made in server.R
      sample<- grid.table(sample)
      vp = viewport(layout.pos.row = 2, layout.pos.col = 1:2)
      grid.text("Your Datatable", vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
      grid.newpage()

      print(plot1()) # Function for the plot you made it in Server.R
      print(plot2())

      dev.off()
    }
  )
于 2016-04-13T07:08:47.467 回答