【问题标题】:Shiny Module app displays tabpanel outside the box layout. Need to resize the tabpanel闪亮的模块应用程序在盒子布局之外显示标签面板。需要调整标签面板的大小
【发布时间】:2022-08-17 01:01:36
【问题描述】:

我有一个闪亮的应用程序,其中标签面板(\'Drug\')显示在盒子布局之外。我正在使用闪亮的模块来模块化我的代码。 Drug 部分有一个它自己的模块,并且有一个主模块是子模块的容器。药物历史和主要模块的 UI 部分如下所示。在模块化代码之前,选项卡面板在框中显示良好。

# 药物历史模块 - UI -------------------------------------------- ---

drug_history_UI <- function(id) {
  ns <- NS(id)
  tabPanel(\"Drug\",
           tabsetPanel(
             type = \"pills\",
             tabPanel(title = \"Previously Diagnosed\",
                      tabsetPanel(
                        type = \"pills\",
                        tabPanel(
                          \"Prior to Index Date\",
                          shinyWidgets::pickerInput(
                            inputId = ns(\"drug_class_selection_prev\"),
                            label = \"Drug Class:\",
                            choices = c(\"ATC 1st\", \"ATC 2nd\", \"ATC 3rd\", \"ATC 4th\", \"ATC 5th\", \"Ingredient\"),
                            selected = c(\"Ingredient\"),
                            width = \"50%\"
                          ),
                          fluidRow(column(5,DT::dataTableOutput(ns(\"truven_prev_med_history_drug_table\"))),
                                   column(7,actionButton(ns(\"resetSelection_drug_tbl_prev\"), label = \"Click to reset row selection\" ,class = \"btn-light\"),
                                          plotlyOutput(ns(\"drug_bar_distr_plot_prev\"),height = 600),
                                          plotlyOutput(ns(\"drug_cleveland_plot_prev\"), height = 600)),
                                   column(12,htmlOutput(ns(\"count_pat_w_comb_trt_prev\")))
                          )
                        )
                        ,
                        tabPanel(\"During Index Date\",
                                 fluidRow(
                                   column(5,DT::dataTableOutput(ns(\"truven_prev_med_history_drug_era_table\"))),
                                   column(7,actionButton(ns(\"resetSelection_drug_era_tbl_prev\"), label = \"Click to reset row selection\" ,class = \"btn-light\"),
                                          plotlyOutput(ns(\"drug_era_bar_distr_plot_prev\"),height = 600),
                                          plotlyOutput(ns(\"drug_era_cleveland_plot_prev\"), height = 600)),
                                   column(12, htmlOutput(ns(\"count_pat_w_comb_trt_drug_era_prev\")))
                                 )
                                 )
                      )),
             tabPanel(title = \"Newly Diagnosed\",
                      tabsetPanel(
                        type = \"pills\",
                        tabPanel(
                          \"Prior to Index Date\",
                          shinyWidgets::pickerInput(
                            inputId = ns(\"drug_class_selection_new\"),
                            label = \"Drug Class:\",
                            choices = c(\"ATC 1st\", \"ATC 2nd\", \"ATC 3rd\", \"ATC 4th\", \"ATC 5th\", \"Ingredient\"),
                            selected = c(\"Ingredient\"),
                            width = \"50%\"
                          ),
                          fluidRow(column(5,DT::dataTableOutput(ns(\"truven_new_med_history_drug_table\"))),
                                   column(7,actionButton(ns(\"resetSelection_drug_tbl_new\"), label = \"Click to reset row selection\" ,class = \"btn-light\"),
                                          plotlyOutput(ns(\"drug_bar_distr_plot_new\"),height = 600),
                                          plotlyOutput(ns(\"drug_cleveland_plot_new\"), height = 600)),
                                   column(12,htmlOutput(ns(\"count_pat_w_comb_trt_new\")))
                          )
                        )
                        ,
                        tabPanel(\"During Index Date\",
                                 fluidRow(
                                   column(5,DT::dataTableOutput(ns(\"truven_new_med_history_drug_era_table\"))),
                                   column(7,actionButton(ns(\"resetSelection_drug_era_tbl_new\"), label = \"Click to reset row selection\" ,class = \"btn-light\"),
                                          plotlyOutput(ns(\"drug_era_bar_distr_plot_new\"),height = 600),
                                          plotlyOutput(ns(\"drug_era_cleveland_plot_new\"), height = 600)),
                                   column(12, htmlOutput(ns(\"count_pat_w_comb_trt_drug_era_new\")))
                                 )
                                 )
                      ))
           ))
  
}

主模块

medical_history_UI <- function(id) {
  ns <- NS(id)
  fluidRow(
  box(
    h3(\"Previously Diagnosed Patients\", align = \"center\"),
    h4(textOutput(ns(\"mh_prev_truven_total_projected\")), align = \"center\"),
    h4(textOutput(ns(\"mh_prev_truven_total_observed\")), align = \"center\"),
    width = 6
  ),
  box(
    h3(\"Newly Diagnosed Patients\", align = \"center\"),
    h4(textOutput(ns(\"mh_inc_truven_total_projected\")), align = \"center\"),
    h4(textOutput(ns(\"mh_inc_truven_total_observed\")), align = \"center\"),
    width = 6
  ),
  astellasTabsetPanel(
    type = \"pills\",
    id = \"med_history\",
    # Drug Panel
    drug_history_UI(ns(\"drug_history\")),
    # Condition Panel
    condition_UI(ns(\"condition_history\")),
    # Procedure Panel
    procedure_UI(ns(\"procedure_history\")),
    # Charlson Comorbidity Panel
    CCI_UI(ns(\"CCI\")),
    tags$head(
      tags$script(
        \'
                                var dimension = [0, 0];
                                $(document).on(\"shiny:connected\", function(e) {
                                    dimension[0] = window.innerWidth;
                                    dimension[1] = window.innerHeight;
                                    Shiny.onInputChange(\"dimension\", dimension);
                                });
                                $(window).resize(function(e) {
                                    dimension[0] = window.innerWidth;
                                    dimension[1] = window.innerHeight;
                                    Shiny.onInputChange(\"dimension\", dimension);
                                });
                            \'
      )
    )
  ))
}

    标签: r shiny tabs shinydashboard shinymodules


    【解决方案1】:

    在主模块中添加流体页()和流体行()使标签对齐。

    medical_history_UI <- function(id) {
      ns <- NS(id)
      fluidPage(
      fluidRow(
      box(
        h3("Previously Diagnosed Patients", align = "center"),
        h4(textOutput(ns("mh_prev_truven_total_projected")), align = "center"),
        h4(textOutput(ns("mh_prev_truven_total_observed")), align = "center"),
        width = 6
      ),
      box(
        h3("Newly Diagnosed Patients", align = "center"),
        h4(textOutput(ns("mh_inc_truven_total_projected")), align = "center"),
        h4(textOutput(ns("mh_inc_truven_total_observed")), align = "center"),
        width = 6
      ),
      astellasTabsetPanel(
        type = "pills",
        id = "med_history",
        # Drug Panel
        drug_history_UI(ns("drug_history")),
        # Condition Panel
        condition_UI(ns("condition_history")),
        # Procedure Panel
        procedure_UI(ns("procedure_history")),
        # Charlson Comorbidity Panel
        CCI_UI(ns("CCI")),
        tags$head(
          tags$script(
            '
                                    var dimension = [0, 0];
                                    $(document).on("shiny:connected", function(e) {
                                        dimension[0] = window.innerWidth;
                                        dimension[1] = window.innerHeight;
                                        Shiny.onInputChange("dimension", dimension);
                                    });
                                    $(window).resize(function(e) {
                                        dimension[0] = window.innerWidth;
                                        dimension[1] = window.innerHeight;
                                        Shiny.onInputChange("dimension", dimension);
                                    });
                                '
          )
        )
      )))
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2017-11-26
      • 2018-08-05
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多