css - R Shiny CondtionalPanel 不使用 CSS 样式表

标签 css r shiny rpivottable

我正在使用 R Shiny 构建网络应用程序。

我使用 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 被 pivotTable 生成的 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;
}

希望这对您有所帮助!

关于css - R Shiny CondtionalPanel 不使用 CSS 样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47927876/

相关文章:

r - 如何在 Shiny 应用程序的 selectModUI 中更新传单 map ?

R shiny : how to not update all input elements of a matrix created in server. r(显然隔离不够)

jquery - 有人知道有一个带有 jQ​​uery 验证的自定义单选按钮/复选框实现吗?

r - 合并列并创建另一列以指定源

c - 设置 R 包中动态链接库的目录路径

r - 根据索引连接(粘贴)元素

R:按背景图像顺序绘制许多图的有效方法

html - CSS Slider - 悬停功能而不是点击

javascript - 使内容展开为空的 div

javascript - 选择表中的最后一个元素