downloadButton导致其他Shiny元素消失

时间:2016-08-02 18:36:22

标签: r shiny

我在名为app.R的文件中有一些简单的R Shiny代码。运行此代码时,daterange6daterange12不会显示。但如果我对downloadButton中的ui行之一进行评论,那么daterange6daterange12似乎都很好。那是为什么?

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem('6 Month', tabName='6M'),
      menuItem('12 Month', tabName='12M')
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName='6M',
        h1("6 Month"),
        sidebarLayout(
          sidebarPanel(width=3, fixed=T,
            downloadButton('downloadData6', 'Download Data'),
            uiOutput('daterange6')
          ),
          mainPanel()
        )
      ),
      tabItem(tabName='12M',
        h1("12 Month"),
        sidebarLayout(
          sidebarPanel(width=3, fixed=T,
            downloadButton('downloadData6', 'Download Data'),
            uiOutput('daterange12')
          ),
          mainPanel()
        )
      )
    )
  )
)

server <- function(input, output, session) {
  output$daterange6 <- renderUI({
    dateRangeInput(inputId='daterange6', 
      label='Select Period', 
      min="2002-01-01", max="2010-01-01",
      start = "2002-01-01", end = "2009-01-01", 
      startview='year'
    )
  })

  output$daterange12 <- renderUI({
    dateRangeInput(inputId='daterange12', 
      label='Select Period', 
      min="2002-01-01", max="2010-01-01",
      start = "2002-02-01", end = "2009-12-01", 
      startview='year'
    )
  })
}    

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

您的问题似乎与ID有关。您对downloadButton具有相同的ID,只需更改名称即可。

除非可以确保不会同时呈现具有相同id的两个元素,否则请始终尝试为每个元素设置唯一ID以避免此类意外行为。