1

当 input$variable 更改 uiOutput(1) 和 uiOutput(2) 同时呈现?有什么办法不同步地逐步渲染吗?

以下是我想要的步骤。

1)输入变量变化

2) uiOutput(1) 渲染

3) uiOutput(2) 渲染

当输入变量更改闪亮页面无法正常工作时。但调整页面窗口大小后,屏幕显示正确。每次更改输入值时,我都必须重新校准页面大小。

用户界面

library(shiny)
library(shinydashboard)

sidebar <- dashboardSidebar(  
  radioButtons(inputId = "sidebar_data_sell", 
               label = "", 
               choices = c("Sell-in" = "sell_in", "Sell-out" = "sell_out"),
               selected = "sell_out", 
               inline = TRUE),
  uiOutput("summary_sidebar_ui")
)


ui <- dashboardPage(
  dashboardHeader(title = h5("Hi")),
  sidebar,
  uiOutput("dashboard_body")
)

服务器.R

convertMenuItem <- function(mi, tabName) {
  mi$children[[1]]$attribs['data-toggle'] = "tab"
  mi$children[[1]]$attribs['data-value'] = tabName
  mi
}

out_product_main <- function() {
  list(
    fluidPage(h5("product")))
}

product_items <- function() {
  list(
    selectInput("product_product_sell", 
                "product", 
                choices = list("product1" = "prd1", "product2" = "prd2"), 
                selected = c("prd1"))
  )
}

in_overview_main <- function() {
  list(
    fluidPage(h5("overview")))
}

overview_items <- function() {
  list(
    radioButtons("overview_period_sell", 
                 "period", 
                 choices = c("year","month"), 
                 inline = TRUE, 
                 selected = "month")
  )
}

shinyServer(function(input, output) {
  output$summary_sidebar_ui <- renderUI({
    if (input$sidebar_data_sell == "sell_in")
    {
      sidebarMenu(id = "summary_item",
                  convertMenuItem(menuItem("Overview", 
                                           tabName = "in_overview",
                                           icon = icon("signal", lib = 'font-awesome'),
                                           overview_items()),
                                  tabName = 'in_overview'))
    }
    else{
      sidebarMenu(id = "p_analysis_item",
                  convertMenuItem(menuItem("Product", 
                                           tabName = "out_product", 
                                           icon = icon("product-hunt", lib='font-awesome'), 
                                           product_items()), 
                                  tabName = 'out_product')
      )
    }


  })

  output$dashboard_body <- renderUI({
    if (input$sidebar_data_sell == "sell_in") {
      dashboardBody(tabItems(tabItem("in_overview", in_overview_main())))
    }
    else {
      dashboardBody(tabItems(tabItem("out_product", out_product_main())))
    }
  })

})
4

0 回答 0