我在名为app.R
的文件中有一些简单的R Shiny代码。运行此代码时,daterange6
和daterange12
不会显示。但如果我对downloadButton
中的ui
行之一进行评论,那么daterange6
和daterange12
似乎都很好。那是为什么?
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)
答案 0 :(得分:0)
您的问题似乎与ID有关。您对downloadButton
具有相同的ID,只需更改名称即可。
除非可以确保不会同时呈现具有相同id的两个元素,否则请始终尝试为每个元素设置唯一ID以避免此类意外行为。