简体   繁体   English

downloadButton导致其他Shiny元素消失

[英]downloadButton causing other Shiny elements to disappear

I have some simple R Shiny code as below in a file named app.R . 我在名为app.R的文件中有一些简单的R Shiny代码,如下所示。 When I run this code, daterange6 and daterange12 do not appear. 当我运行此代码时, daterange6daterange12不会出现。 But if I comment one of the downloadButton lines in ui then both daterange6 and daterange12 appear just fine. 但是,如果我在ui注释了downloadButton行之一,则daterange6daterange12都很好。 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. 看来您的问题与ID有关。 You have the same id for both downloadButton , just change the name. 两个downloadButton ID相同,只需更改名称即可。

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. 除非您可以确保不会同时呈现两个具有相同id的元素,否则请始终尝试为每个元素使用唯一的id以避免这种意外行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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