【发布时间】:2019-11-24 01:12:21
【问题描述】:
我的 Shiny APP 有一个简单的结构如下:
ui <- fluidPage(
dashboardPage(
dashboardHeader(title = "My App"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard",
selectInput('location', 'Please Select a Location', choices= c("A", "B", "C")),
downloadButton(outputId = 'download', lable = "Downlaod"),
menuItem("Widgets", tabName = "widgets", badgeLabel = "new", badgeColor = "green")
)),
# dashboardBody first try (works no problem):
dashboardBody(DT::dataTableOutput(outputId = 'mytable'))
# dashboardBody second try (data table does not appear):
dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
DT::dataTableOutput(outputId = 'mytable')),
tabItem(tabName = "widgets",
h2("Widgets tab content"))
)))
server <- shinyServer(function(input, output, session){
output$mytable<- DT::renderDataTable({```some calculation```})
output$downloadcsv <- downloadHandler(
filename = function(){paste0(sys.Date(),'-mytable.csv')},
content = function(file) {write.csv(```the table from renderDataTable step```, file)}
)}
如您所见,该应用程序包含两个不同的“页面”,其中第一个是依赖于selectInput 的数据表。
如果我不使用tabItem 包装我的应用程序,它会完美运行。但是,一旦我在tabItem 下编写它,该应用程序只显示 "Widgets tab content" 这是第二个选项卡的内容并且根本不填充数据表(而下载按钮仍然作品)。
我也试过在tabName = "dashboard"后面加class='active',但还是不行。另外,我没有收到任何错误消息。
我想知道是否有人知道我走错了哪一步?任何帮助将不胜感激!
【问题讨论】:
-
您能否更正您在应用中渲染“output$downloadcsv”的位置。
标签: r shiny shinydashboard