从RShiny CSS SortableJS中删除换行符

ssgvzors  于 2022-12-30  发布在  其他
关注(0)|答案(1)|浏览(122)

我这里有一个99%工作最小化的例子。我唯一想改变的是有排名号码旁边的字母,而不是在上面的行。

library(shiny)
library(sortable)

addDiv <- function(x) {lapply(x,function(x){tags$div(x)})}

ui <- fluidPage(
  
  tags$head(
    tags$style(HTML('
      #rank_list_basic > div {cursor: move; #fallback
                        cursor: grab; cursor: pointer;}
      #rank_list_basic {list-style-type: none;  counter-reset: css-counter 0;}
      #rank_list_basic > div {counter-increment: css-counter 1;}
      #rank_list_basic > div:before {content: counter(css-counter) ". ";}
      ')
    )
  ),
  
  fluidRow(
            rank_list(
              text = "Drag the items in any desired order",
              labels = addDiv(c("A","B","C","D","E")),
              input_id = "output",
              css_id = "rank_list_basic"
            ),
          verbatimTextOutput("results_basic")
      )
)

server <- function(input, output) {
  output$results_basic <- renderPrint({
    input$output
  })

}

shinyApp(ui, server)
1zmg4dgp

1zmg4dgp1#

您只需将labels放入list中,而不是使用addDiv

library(shiny)
library(sortable)

addDiv <- function(x) {lapply(x,function(x){tags$div(x)})}

ui <- fluidPage(
  
  tags$head(
    tags$style(HTML('
      #rank_list_basic > div {cursor: move; #fallback
                        cursor: grab; cursor: pointer;}
      #rank_list_basic {list-style-type: none;  counter-reset: css-counter 0;}
      #rank_list_basic > div {counter-increment: css-counter 1;}
      #rank_list_basic > div:before {content: counter(css-counter) ". ";}
      ')
    )
  ),
  
  fluidRow(
    rank_list(
      text = "Drag the items in any desired order",
      labels = list("A","B","C","D","E"),
      input_id = "output",
      css_id = "rank_list_basic"
    ),
    verbatimTextOutput("results_basic")
  )
)

server <- function(input, output) {
  output$results_basic <- renderPrint({
    input$output
  })
  
}

shinyApp(ui, server)

相关问题