如何将通过排序生成的对象馈送到列表,向量或数据框架中?

发布于 2025-02-01 10:13:12 字数 1606 浏览 3 评论 0原文

我正在尝试R Shiny软件包可排序。我正在尝试将可重复的代码中的bucket_list生成的元素添加到列表,向量或数据框架中,以准备在我开发此过程时为进一步的数据操作做准备。我不知道下面由buck_list生成了哪种对象。理想情况下,我需要将数值排名(下面的1和2)划分为一列,然后将池ID(B和A)划入单独的数据帧列中。

如何将这些元素馈送到列表/向量/数据框中?底部的图像更好地说明了。

可重复的代码:

library(shiny)
library(sortable)   

ui <- 
  fluidPage(
    tags$head(tags$style(HTML("
      .column_2 {
        counter-reset: rank;                      
      }

      .column_2 .rank-list-item::before {
        counter-increment: rank;                   
        content: counter(rank) '. ';    
      }
    "))),
    htmlOutput("rankingForm"),
    tableOutput("table1")
  
)

server <- function(input, output, session) {
  output$rankingForm <- renderUI({
    fluidRow(
      column(tags$b("Pool Ranking"), width = 12,
             bucket_list(header = "Drag to the right from the Pool below to rank.", 
                         group_name = "bucket_list_group", orientation = "horizontal",
                         add_rank_list("Pool:", 
                                       labels = c("A","B","C","D","E"), 
                                       input_id = "rank_list_1"),
                         add_rank_list("Pool Ranking:", labels = NULL,
                                       input_id = "rank_list_2"))
      )
    )
  })
  
  output$table1 <- renderTable({ranklist2})
  
}

shinyApp(ui=ui, server=server)

“在此处输入图像描述”

I'm trying out R Shiny package sortable. I'm trying to feed the elements generated by the bucket_list in the reproducible code below into either a list, vector, or dataframe, to prepare for further data manipulation as I develop this. I have no idea what sort of object is generated by bucket_list below. Ideally, I need to strip out the numerical ranking (the 1 and 2 below) into one column and the Pool ID (B and A) into separate dataframe columns.

How can I feed those elements into a list/vector/dataframe? The image at the bottom better illustrates.

Reproducible code:

library(shiny)
library(sortable)   

ui <- 
  fluidPage(
    tags$head(tags$style(HTML("
      .column_2 {
        counter-reset: rank;                      
      }

      .column_2 .rank-list-item::before {
        counter-increment: rank;                   
        content: counter(rank) '. ';    
      }
    "))),
    htmlOutput("rankingForm"),
    tableOutput("table1")
  
)

server <- function(input, output, session) {
  output$rankingForm <- renderUI({
    fluidRow(
      column(tags$b("Pool Ranking"), width = 12,
             bucket_list(header = "Drag to the right from the Pool below to rank.", 
                         group_name = "bucket_list_group", orientation = "horizontal",
                         add_rank_list("Pool:", 
                                       labels = c("A","B","C","D","E"), 
                                       input_id = "rank_list_1"),
                         add_rank_list("Pool Ranking:", labels = NULL,
                                       input_id = "rank_list_2"))
      )
    )
  })
  
  output$table1 <- renderTable({ranklist2})
  
}

shinyApp(ui=ui, server=server)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦屿孤独相伴 2025-02-08 10:13:13

这是在解决I_O昨天评论的解决方案:

library(shiny)
library(sortable)   

ui <- 
  fluidPage(
    tags$head(tags$style(HTML("
      .column_2 {
        counter-reset: rank;                      
      }

      .column_2 .rank-list-item::before {
        counter-increment: rank;                   
        content: counter(rank) '. ';    
      }
    "))),
    htmlOutput("rankingForm"),
    tableOutput("table1")
  
)

server <- function(input, output, session) {
  output$rankingForm <- renderUI({
    fluidRow(
      column(tags$b("Pool Ranking"), width = 12,
             bucket_list(header = "Drag to the right from the Pool below to rank.", 
                         group_name = "bucket_list_group", orientation = "horizontal",
                         add_rank_list("Pool:", 
                                       labels = c("A","B","C","D","E"), 
                                       input_id = "rank_list_1"),
                         add_rank_list("Pool Ranking:", labels = NULL,
                                       input_id = "rank_list_2"))
      )
    )
  })
  
  output$table1 <- renderTable({input$rank_list_2}) # << solution
  
}

shinyApp(ui=ui, server=server)

Here is working the solution incorporating yesterday's comment from I_O:

library(shiny)
library(sortable)   

ui <- 
  fluidPage(
    tags$head(tags$style(HTML("
      .column_2 {
        counter-reset: rank;                      
      }

      .column_2 .rank-list-item::before {
        counter-increment: rank;                   
        content: counter(rank) '. ';    
      }
    "))),
    htmlOutput("rankingForm"),
    tableOutput("table1")
  
)

server <- function(input, output, session) {
  output$rankingForm <- renderUI({
    fluidRow(
      column(tags$b("Pool Ranking"), width = 12,
             bucket_list(header = "Drag to the right from the Pool below to rank.", 
                         group_name = "bucket_list_group", orientation = "horizontal",
                         add_rank_list("Pool:", 
                                       labels = c("A","B","C","D","E"), 
                                       input_id = "rank_list_1"),
                         add_rank_list("Pool Ranking:", labels = NULL,
                                       input_id = "rank_list_2"))
      )
    )
  })
  
  output$table1 <- renderTable({input$rank_list_2}) # << solution
  
}

shinyApp(ui=ui, server=server)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文