gpt4 book ai didi

r - 避免在 sliderTextInput 中重叠文本

转载 作者:行者123 更新时间:2023-12-03 17:29:23 25 4
gpt4 key购买 nike

我正在使用 sliderTextInput来自 shinyWidgets 包。我无法使标签可读。

首先,它们太小了,我已经使用 css 修复了它。但是,现在标签重叠,因此很难阅读它们。

Example of overlapping labels

我希望能够执行以下一项或两项操作:

  • 将文本倾斜 45 或 90 度,以免标签重叠。
  • 减少标签的数量,以便它们之间有更多的空间。我尝试在 choices = 中执行此操作论点,但这会阻止这些选项被选中。我认为这可能与文本而不是数字有关,因此这可能使这不可能。

  • 我试过使用 sliderInput相反,但这会带来不同的问题。我几乎用 this answer 让它工作了,但另一个问题是我有输入服务器端,作为 uiOutput 输入,这是我无法改变的,因为它对于不同的元素很重要。这种方法不适用于链接解决方案 - 我最终得到了足够好的标签,但休息时间是每天而不是每月。

    这是一个精简的示例:

    使用 sliderTextInput(标签重叠)
    library(shinydashboard)
    library(shinyWidgets)
    library(shiny)


    ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
    tags$head(tags$style(type = "text/css", ".irs-grid-text {font-size: 12pt !important;")),
    fluidRow(
    box(uiOutput("month_selection"))
    )
    )
    )

    server <- function(input, output) {
    output$month_selection <- renderUI({
    sliderTextInput(
    inputId = "month_select",
    label = "",
    grid = TRUE,
    force_edges = TRUE,
    choices = seq(from = as.Date("2017-01-01"), to = as.Date("2019-12-31"),by = 30)
    )
    })

    }

    shinyApp(ui, server)

    使用 slider 输入(不运行)

    library(shinydashboard)
    library(shinyWidgets)
    library(shiny)

    monthStart <- function(x) {
    x <- as.POSIXlt(x)
    x$mday <- 1
    as.Date(x)
    }

    ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
    tags$head(tags$style(type = "text/css", ".irs-grid-text {font-size: 12pt !important;")),
    fluidRow(
    box(uiOutput("month_selection"))
    )
    )
    )

    server <- function(input, output) {

    output$month_selection <- renderUI({
    sliderInput(
    inputId = "month_select",
    label = "",
    min = as.Date("2017-01-01"),
    max = as.Date("2019-12-31"),
    value = as.Date("2019-12-31"),
    timeFormat = "%b %Y",
    animate = TRUE
    )
    })

    sliderMonth <- reactiveValues()
    observe({
    sliderMonth$Month <- as.character(monthStart(input$month_select))
    })

    }

    shinyApp(ui, server)

    > Warning: Error in as.POSIXlt.default: do not know how to convert 'x' to class “POSIXlt”

    最佳答案

    解决方案(学分转到 Victor Perrier )取自 shinyWidgets issue由提问者创建。
    文本可以只用 CSS 进行 roteted。类(class).irs-grid-text标识 sliderTextInput 小部件的标签。与 transform可以旋转文本,使其不重叠。

    library(shinydashboard)
    library(shinyWidgets)
    library(shiny)


    ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
    tags$head(tags$style(
    type = "text/css",
    ".irs-grid-text {font-size: 12pt !important; transform: rotate(-90deg) translate(-30px);"
    )),
    fluidRow(
    box(uiOutput("month_selection"), height = "200px")
    )
    )
    )

    server <- function(input, output) {
    output$month_selection <- renderUI({
    sliderTextInput(
    inputId = "month_select",
    label = "",
    grid = TRUE,
    force_edges = TRUE,
    choices = seq(from = as.Date("2017-01-01"), to = as.Date("2019-12-31"), by = 30)
    )
    })
    }

    shinyApp(ui, server)

    关于r - 避免在 sliderTextInput 中重叠文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57511430/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com