Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shiny 数据表的列标题发生移位_Shiny_Dt - Fatal编程技术网

Shiny 数据表的列标题发生移位

Shiny 数据表的列标题发生移位,shiny,dt,Shiny,Dt,当我运行闪亮的应用程序时,数据表的标题会向左移动。见下表。假设此表位于选项卡A上 当我单击其他选项卡(选项卡B),然后再次单击选项卡a时,标题将正确对齐。有关更正的标题,请参见下文 知道是什么引起的吗?下面是我的代码的简化版本。提前谢谢 ui.R library("shinythemes") fluidPage(title = "Segmentation App", theme = shinytheme("spacelab"), navbarPage("Se

当我运行闪亮的应用程序时,数据表的标题会向左移动。见下表。假设此表位于选项卡A上

当我单击其他选项卡(选项卡B),然后再次单击选项卡a时,标题将正确对齐。有关更正的标题,请参见下文

知道是什么引起的吗?下面是我的代码的简化版本。提前谢谢

ui.R

    library("shinythemes")

    fluidPage(title = "Segmentation App", theme = shinytheme("spacelab"),

        navbarPage("Segmentation", id = "allResults",
            tabPanel(value='result_scorecard', title='ScoreCard', 
                     sidebarLayout(
                       sidebarPanel(
                         h4("Select a cluster solution to profile"),
                         width = 3
                       ),

                       mainPanel(
                         verticalLayout(
                           helpText(strong('Summary of Cluster Solutions')),
                           column(DT::dataTableOutput('out_best'), width = 12),                              
                           helpText(strong('ScoreCard Table')),
                           column(DT::dataTableOutput('out_scorecard'), width = 12)

                         )
                       )
                     )
            ),

            tabPanel(value='profile', title='Profile', 
                     verticalLayout(
                         column(DT::dataTableOutput('prop_by_cluster_ind'), width=10)
                      )
            )
        )
    )
function(input, output, session) {

    best_sols <- reactive({
     A <- c(100, 101, 201)
     B <- c(100, 101, 201)
     C <- c(100, 101, 201)
     temp <- as.matrix(cbind(A, B, C))
     colnames(temp) <- c("A", "B", "C")
     rownames(temp) <- c("k=1","k=2","k=3")
     return(temp)
    })

    score_seg <- reactive({
      A <- c("solution=1","solution=2","solution=3","solution=4","solution=5")
      B <- c(100, 101, 201, 333, 444)
      C <- c(100, 101, 201, 333, 444)
      temp <- data.frame(A, B, C)
      colnames(temp) <- c("A", "B", "score_seg")
      return(temp)

    })

    profile_result_ind <- reactive({
      A1 <- c("var1","var2","var3","var4","var5")
      A2 <- c("var1","var2","var3","var4","var5")
      B <- c(100, 101, 201, 333, 444)
      C <- c(100, 101, 201, 333, 444)
      temp <- data.frame(A1, A2, B, C)
      colnames(temp) <- c("","","1","2")
      return(temp)
    })


    # Table 1

    output$out_best <- DT::renderDataTable({
        DT::datatable(best_sols(), caption = "", rownames = TRUE, options = list(autoWidth = TRUE, scrollX = TRUE, columnDefs = list(list(width = '100px', targets = 1)), paging = FALSE, searching = FALSE), selection='none') %>% formatRound(1:5, 3)
      #}
    })

    # Table 2

    output$out_scorecard <- DT::renderDataTable({
        DT::datatable(score_seg(), caption = "", rownames = F, options = list(autoWidth = TRUE, scrollX = TRUE, columnDefs = list(list(width = '200px', targets = 1)), paging = FALSE, searching = FALSE), selection='single') %>% formatRound(1:5, 3)
    })


    # Table 3
    output$prop_by_cluster_ind <- DT::renderDataTable({
        DT::datatable(profile_result_ind(), class= 'compact stripe', caption = '', rownames = F, options = list(autoWidth = TRUE, scrollX = TRUE, columnDefs = list(list(width = '300px', targets = 1), list(className = 'dt-left', targets="_all")), paging = FALSE, searching = FALSE)) %>% formatStyle(as.character(seq(1:2)))   
    }) 
}
server.R

    library("shinythemes")

    fluidPage(title = "Segmentation App", theme = shinytheme("spacelab"),

        navbarPage("Segmentation", id = "allResults",
            tabPanel(value='result_scorecard', title='ScoreCard', 
                     sidebarLayout(
                       sidebarPanel(
                         h4("Select a cluster solution to profile"),
                         width = 3
                       ),

                       mainPanel(
                         verticalLayout(
                           helpText(strong('Summary of Cluster Solutions')),
                           column(DT::dataTableOutput('out_best'), width = 12),                              
                           helpText(strong('ScoreCard Table')),
                           column(DT::dataTableOutput('out_scorecard'), width = 12)

                         )
                       )
                     )
            ),

            tabPanel(value='profile', title='Profile', 
                     verticalLayout(
                         column(DT::dataTableOutput('prop_by_cluster_ind'), width=10)
                      )
            )
        )
    )
function(input, output, session) {

    best_sols <- reactive({
     A <- c(100, 101, 201)
     B <- c(100, 101, 201)
     C <- c(100, 101, 201)
     temp <- as.matrix(cbind(A, B, C))
     colnames(temp) <- c("A", "B", "C")
     rownames(temp) <- c("k=1","k=2","k=3")
     return(temp)
    })

    score_seg <- reactive({
      A <- c("solution=1","solution=2","solution=3","solution=4","solution=5")
      B <- c(100, 101, 201, 333, 444)
      C <- c(100, 101, 201, 333, 444)
      temp <- data.frame(A, B, C)
      colnames(temp) <- c("A", "B", "score_seg")
      return(temp)

    })

    profile_result_ind <- reactive({
      A1 <- c("var1","var2","var3","var4","var5")
      A2 <- c("var1","var2","var3","var4","var5")
      B <- c(100, 101, 201, 333, 444)
      C <- c(100, 101, 201, 333, 444)
      temp <- data.frame(A1, A2, B, C)
      colnames(temp) <- c("","","1","2")
      return(temp)
    })


    # Table 1

    output$out_best <- DT::renderDataTable({
        DT::datatable(best_sols(), caption = "", rownames = TRUE, options = list(autoWidth = TRUE, scrollX = TRUE, columnDefs = list(list(width = '100px', targets = 1)), paging = FALSE, searching = FALSE), selection='none') %>% formatRound(1:5, 3)
      #}
    })

    # Table 2

    output$out_scorecard <- DT::renderDataTable({
        DT::datatable(score_seg(), caption = "", rownames = F, options = list(autoWidth = TRUE, scrollX = TRUE, columnDefs = list(list(width = '200px', targets = 1)), paging = FALSE, searching = FALSE), selection='single') %>% formatRound(1:5, 3)
    })


    # Table 3
    output$prop_by_cluster_ind <- DT::renderDataTable({
        DT::datatable(profile_result_ind(), class= 'compact stripe', caption = '', rownames = F, options = list(autoWidth = TRUE, scrollX = TRUE, columnDefs = list(list(width = '300px', targets = 1), list(className = 'dt-left', targets="_all")), paging = FALSE, searching = FALSE)) %>% formatStyle(as.character(seq(1:2)))   
    }) 
}
功能(输入、输出、会话){
最好的解决办法我想出来了


如果我们将autoWidth选项更改为FALSE,标题将正确对齐。

我有一个像您这样的长行名表,并且在偏移列名方面也有类似的问题,但是设置autoWidth=FALSE并没有解决问题。我发现这是由scrollX=TRUE引起的。我更改了>ScrollX=FALSE并将数据表包装在带有溢出的div中-x=TRUE以恢复滚动功能:

div(style="overflow-x:auto",renderDataTable({tableName},options=list(scrollX=FALSE))

我也有同样的问题,
autoWidth=FALSE
解决了这个问题,但是数据帧使用了所有可用的宽度,请问还有其他解决方案吗?
autoWidth
如果需要手动指定列宽,请参见。必须有其他解决方案。