绘图属性将从一个tabPanel更改为Shiny仪表板中的另一个tabPanel

时间:2016-12-25 18:57:01

标签: r shiny nvd3.js rcharts

我正在创建一个Shiny仪表板应用程序,对于菜单项我创建了两个选项卡面板,如下面的输出所示。

代码:

library(shinydashboard)
library(shiny)
library(rAmCharts)
library(rCharts)
data(data_funnel)

body <- dashboardBody(
  #tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
  tabItems(
    tabItem(tabName = "summary",
            tabsetPanel(
              tabPanel("tab1",  
                       fluidRow(
                         box(
                           title = "Box title", width = 5, status = "primary",
                           amChartsOutput(outputId = "amfunnel",width = "100%",height = "350px")
                         ),
                         box(
                           status = "warning", width = 5,
                           showOutput("stacked","nvd3")
                         ),
                         box(
                           status = "warning", width = 2, 
                           "Box Content"
                         )

                       )
              ),
              tabPanel("tab2",
                       fluidRow(
                         box(
                           title = "Box title", width = 7, status = "primary",
                           amChartsOutput(outputId = "ambarplot",width = "100%",height = "350px")
                         ),
                         box(
                           status = "warning", width = 3,
                           showOutput("piechart","nvd3")
                         ),
                         box(
                           status = "warning", width = 2, 
                           "Box Content"
                         )
                       )   
              )
            )  

      )
  )
)  
server <- function(input, output) {

  output$amfunnel <-  renderAmCharts({
    amFunnel(data = data_funnel, inverse = FALSE,margin_right = 0, margin_left = 190, label_side = "left")
  })

  output$stacked <- renderChart2({
    hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
    n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarHorizontalChart")
    n1$params$height = 390 
    n1$params$width = 450
    n1
  })

  output$ambarplot <- renderAmCharts({
    dataset <- data.frame(get(x = "USArrests", pos = "package:datasets"))
    amBarplot(y = c("Murder", "Assault", "UrbanPop", "Rape"), data = dataset, stack_type = "regular",horiz = TRUE,legend=TRUE)
  })

  output$piechart <- renderChart2({
    p1 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
    p1$params$height = 390 
    p1$params$width = 300
    p1
  })

}  

# We'll save it in a variable `ui` so that we can preview it in the console
ui <- dashboardPage(
  dashboardHeader(title = "Mixed layout"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Summary",tabName = "summary")
    )
  ),
  body
)

# Preview the UI in the console
shinyApp(ui = ui, server = server)

输出如下:

tab1

tab2

我面临的问题是当我从tab1导航时 - &gt; tab2再次来自tab2 - &gt; tab1,tab1的box2属性被tab2的box2属性覆盖。

请告诉我您对如何解决此问题的想法。

0 个答案:

没有答案