【问题标题】:R Shiny CondtionalPanel not using CSS stylesheetR Shiny CondtionalPanel 不使用 CSS 样式表
【发布时间】:2018-06-04 07:16:15
【问题描述】:

我正在使用 R Shiny 构建一个 Web 应用程序。

我正在使用 conditionPanels(有时)根据对象 df 的类型显示数据透视表。

如下所示,如果透视表显示在条件面板中,则简单地忽略 css 并以默认样式显示透视表。但是,如果我包含第二个数据透视表,而不是在条件面板中呈现,则两个数据透视表都采用 custom.css 中描述的样式。

当没有第二个数据透视表时,如何确保样式表用于第一个数据透视表?

# Server.R
server <- shinyServer(function(input, output,session){
  df <- data.frame(col1 = c('a','b','c'),
                   col2 = c(1,2,3))

  ## Output PivotTable
  output$pivotTable <- rpivotTable::renderRpivotTable({
    rpivotTable(data = df,
                aggregatorName = 'Sum',
                rendererName = 'Table')
  })

  ## Output PivotTable2
  output$pivotTable2 <- rpivotTable::renderRpivotTable({
    rpivotTable(data = df,
                aggregatorName = 'Sum',
                rendererName = 'Table')
  })

  condition <- ifelse(is.data.frame(df), 'true', 'false')

  ## Output PivotTable
  output$panelTable <- renderUI({
    conditionalPanel(
      condition,
      rpivotTableOutput("pivotTable")
    )
  })
})



# UI.R:
ui <- dashboardPage(
  title = "",

  ## Header content + dropdownMenu
  dashboardHeader(
    title = tags$b(""),
    titleWidth = 250
  ),

  ## Sidebar content
  dashboardSidebar(
    width = 250,
    sidebarMenu(
      id = "tabs",
      menuItem("tab1", tabName = "tab", icon = icon("table"))
    )
  ),

  ## Body content
  dashboardBody(
    tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")),
    tabItems(
      tabItem(tabName = "tab",
        div(
          uiOutput('panelTable')
        ),
        div(
          rpivotTableOutput("pivotTable2")
        )
      )
    )
  )
)


# Create Shiny object
shinyApp(ui = ui, server = server)

CSS:

/* Adjust css of pivot table */
#pivotTable{ 
  overflow-x: scroll; 
  overflow-y: scroll;
}

.pvtRows, .pvtCols {
  background: #FAFAFA none repeat scroll 0 0;
}

table.pvtTable tbody tr th, table.pvtTable thead tr th {
  background: #FFFFFF;
}

.pvtAxisContainer li span.pvtAttr {
    background: rgba(147,255,53,0.8);
}

【问题讨论】:

  • 您好,您的回答对您有帮助吗?还是问题仍未解决?

标签: css r shiny rpivottable


【解决方案1】:

我认为您可以尝试在 div 中定义类。

例如:

div(class = "pvtRows pvtAxisContainer",
  uiOutput('panelTable')
)

【讨论】:

    【解决方案2】:

    您好,您的问题是,您的 css 已被生成的 css 规则推翻为数据透视表,从而在每个类似这样的规则后添加 !important

    #pivotTable{ 
      overflow-x: scroll; 
      overflow-y: scroll;
    }
    
    .pvtRows, .pvtCols {
      background: #FAFAFA none repeat scroll 0 0 !important;
    }
    
    table.pvtTable tbody tr th, table.pvtTable thead tr th {
      background: #FFFFFF!important;
    }
    
    .pvtAxisContainer li span.pvtAttr {
        background: rgba(147,255,53,0.8) !important;
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-10-12
      • 2014-06-06
      • 2021-12-13
      • 1970-01-01
      • 2013-07-23
      • 2021-08-28
      • 1970-01-01
      • 2015-10-24
      • 2017-10-19
      相关资源
      最近更新 更多