简体   繁体   中英

downloadButton causing other Shiny elements to disappear

I have some simple R Shiny code as below in a file named app.R . When I run this code, daterange6 and daterange12 do not appear. But if I comment one of the downloadButton lines in ui then both daterange6 and daterange12 appear just fine. Why is that?

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)

It seems that your problem is related to the Ids. You have the same id for both downloadButton , just change the name.

Always try to have a unique id for each element to avoid this kind of unexpected behavior, unless you can make sure that two elements with the same id will not be rendered at the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM