【问题标题】:Remove bold in a shiny sidebar in R在 R 的闪亮侧边栏中删除粗体
【发布时间】:2018-06-28 17:38:55
【问题描述】:

我是 Shiny 的新手,不知道如何“取消加粗”标签(所附屏幕截图中的进给率和操作)。这是我的 UI 部分代码:

ui <- fluidPage(titlePanel(""),
                sidebarLayout(
                  sidebarPanel(
                    # adding the new div tag to the sidebar            
                    tags$div(class="header", checked=NA,
                             tags$h4(strong("Duty"))),
                    selectInput('id1', 'Feed rate (m^3/h)', c("All", main$metric[1:3])),
                    selectInput('id2', 'Operation', c("All", main$metric[4:5])),
                  mainPanel(DT::dataTableOutput("table"))
                ))

这是截图:

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您可以通过adding your own style sheet 对您的 Shiny 应用执行此操作。首先我们给侧边栏面板一个类sidebar,这样我们就可以引用它。然后我们可以将以下内容添加到文件www/style.css

    .sidebar label {
      font-weight: 400;
    }
    

    最后我们将fluidPagetheme参数设置为“style.css”。

    ui <- fluidPage(theme="style.css", titlePanel(""),
       # content here
    ))
    

    结果应该是这样的:

    【讨论】:

    • 谢谢,西蒙!抱歉这个愚蠢的问题,但我不确定在哪里可以找到我的 Shiny 文件夹:|
    • 您应该查找您的 app.R(或 ui.R 和 server.R)文件所在的文件夹。如果您使用的是 RStudio,您应该能够将鼠标悬停在打开文件的选项卡名称上以查看文件的完整路径。
    • 所以在我的R脚本所在的文件夹中,我只需要添加www文件夹并将style.css文件保存在那里?我试过了,但没有用。
    • 记得在fluidPage()中也要设置theme="style.css"
    【解决方案2】:

    这是另一种选择(您不必创建文件)

    library(shiny)
    
    remove_bold <-"
    #expr-container label {
      font-weight: 400;
    }
    "
    
    ui <- fluidPage(
      
      titlePanel("My app"),
      
      sidebarLayout(
        sidebarPanel(
          tags$style(remove_bold), ####### NEW CODE
          tags$div(id = "expr-container", ####### NEW CODE
          textInput(inputId = "data2", "Data1", value = "data"))
        ),
        
        mainPanel(
        )
      )
    )
    
    
    server <- function(input, output) {
    }
    
    shinyApp(ui = ui, server = server)
    

    在这篇文章中受到启发:How to change the pickerinput label to fine instead of bold

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 2019-11-13
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2017-04-23
      • 2021-11-11
      相关资源
      最近更新 更多