运行可排序软件包时如何补充存储库列表?

发布于 2025-02-01 12:18:52 字数 1754 浏览 3 评论 0原文

我正在探索如何可视化数学过程(一系列顺序计算)的方法,并且可排序的软件包可能是通过修改的答案。以下可再现的代码是从如何在线找到可排序及其参考手册的基本示例中获取的(添加了表输出,因此我可以开始操纵数据框架)。

我试图查看是否有一种方法可以不耗尽存储库列表,因为用户从左图中拖动并掉落(在我的示例中标记为“池”)到右面板(在我的示例中标记为“池排名”)。因此,查看底部的图像,用户可以根据需要拖动/删除项目A,B,C,D,E。然后,由于拖动/掉落的元素的重复,右“拖动到”面板的增长大于“拖动”面板的更长。

这可以分类吗?怎么办?还是我应该看其他软件包?

如果我能弄清楚这一点,我的下一步将是添加来自数学公式面板的另一个“拖动”,以在拖动到标签元素的右侧拖动A -E。

可重复可重复的代码:

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"),
    helpText(h5(strong("Output to table:"))),
    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})
  
}

shinyApp(ui=ui, server=server)

I'm exploring ways to visualize a mathematical process (a series of sequential computations) and the sortable package may be the answer, with modifications. The below reproducible code is pulled from the basic examples of how to use sortable found online and in its reference manual (with a table output added so I can start manipulating the data frame).

I'm trying to see if there's a way to not deplete the bucket list as the user drags and drops from the left panel (labeled "Pool" in my example) to the right panel (labeled "Pool Ranking" in my example). So looking at the image at the bottom, the user can drag/drop items A, B, C, D, E, as many times as desired. The right "drag to" panel then grows longer than the left "drag from" panel due to the repetition of elements dragged/dropped.

Is this possible in sortable? How can it be done? Or should I be looking at other packages instead?

If I can figure this out, my next step will be to add another "drag from" panel of mathematical formulas to drag to the right of the dragged-to label elements A - E.

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"),
    helpText(h5(strong("Output to table:"))),
    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})
  
}

shinyApp(ui=ui, server=server)

enter image description here

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

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

发布评论

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

评论(1

ま昔日黯然 2025-02-08 12:18:52

通过这些列出的stackoverflow帖子和解决方案,我到达了底部显示的“工作解决方案”:

相关帖子:

vladimir_orbucina请求, https://github.com/rstudio/sortable/sorsues/45
来自HTML/CSS的元素以及R数据框架?
如何使可排序的包中的标签add_rank_list函数反应?
态将编号订购到这个简单的可排序示例?

和一个重要链接来解释克隆: https://rstudio.github.io/sortable/articles/cloning.html

工作解决方案:

library(shiny)
library(sortable)
library(htmlwidgets)

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

ui <- fluidPage(

# Below solution provided by I|O on Jun 1, 2022:  
  tags$head(
    tags$style(HTML('
      #drag_from > div {cursor: move; #fallback
                        cursor: grab; cursor: pointer;
                        }
      #drag_to > div {cursor: move; #fallback
                      cursor: grab; cursor: pointer;
                      }                
      #drag_to {list-style-type: none;  counter-reset: css-counter 0;}
      #drag_to > div {counter-increment: css-counter 1;}
      #drag_to > div:before {content: counter(css-counter) ". ";}
      ')
    )
  ),
  
  div(
    style = "margin-top: 2rem; width: 60%; display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; align-items: start;",

    div(
      div(
        class = "panel panel-default",
        div(class = "panel-heading", "Drag from here"),
        div(
          class = "panel-body",
          id = "drag_from",
          icons(c("A", "B", "C", "D", "E"))
        )
      ),
    ),
    div(
      div(
        class = "panel panel-default",
        div(class = "panel-heading", "Drag to here"),
        div(
          class = "panel-body",
          id = "drag_to"
        )
      )
    )
  ),
  sortable_js(
    "drag_from",
    options = sortable_options(
      group = list(
        pull = "clone",
        name = "group1",
        put = FALSE
      )
    )
  ),
  sortable_js(
    "drag_to",
    options = sortable_options(
      group = list(
        group = "group1",
        put = TRUE,
        pull = TRUE
      ),
      onSort = sortable_js_capture_input(input_id = "selected") # << solution by stefan on Jun 01, 2022
    )
  ),
  helpText(h5(strong("Output to table:"))),
  tableOutput("table1")
)

server <- function(input, output) {
  output$table1 <- renderTable({input$selected})
}

shinyApp(ui, server)

Through these listed StackOverflow posts and solutions, I arrived at the "Working solution" shown at the bottom:

Related posts:

vladimir_orbucina request at https://github.com/rstudio/sortable/issues/45 and
How to pull list elements from HTML/CSS and into an R data frame? and
How to make the label in the sortable package add_rank_list function reactive? and
Any creative ways to add rank ordering numbering to this simple sortable package example?

And an important link that explains cloning: https://rstudio.github.io/sortable/articles/cloning.html

Working solution:

library(shiny)
library(sortable)
library(htmlwidgets)

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

ui <- fluidPage(

# Below solution provided by I|O on Jun 1, 2022:  
  tags$head(
    tags$style(HTML('
      #drag_from > div {cursor: move; #fallback
                        cursor: grab; cursor: pointer;
                        }
      #drag_to > div {cursor: move; #fallback
                      cursor: grab; cursor: pointer;
                      }                
      #drag_to {list-style-type: none;  counter-reset: css-counter 0;}
      #drag_to > div {counter-increment: css-counter 1;}
      #drag_to > div:before {content: counter(css-counter) ". ";}
      ')
    )
  ),
  
  div(
    style = "margin-top: 2rem; width: 60%; display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; align-items: start;",

    div(
      div(
        class = "panel panel-default",
        div(class = "panel-heading", "Drag from here"),
        div(
          class = "panel-body",
          id = "drag_from",
          icons(c("A", "B", "C", "D", "E"))
        )
      ),
    ),
    div(
      div(
        class = "panel panel-default",
        div(class = "panel-heading", "Drag to here"),
        div(
          class = "panel-body",
          id = "drag_to"
        )
      )
    )
  ),
  sortable_js(
    "drag_from",
    options = sortable_options(
      group = list(
        pull = "clone",
        name = "group1",
        put = FALSE
      )
    )
  ),
  sortable_js(
    "drag_to",
    options = sortable_options(
      group = list(
        group = "group1",
        put = TRUE,
        pull = TRUE
      ),
      onSort = sortable_js_capture_input(input_id = "selected") # << solution by stefan on Jun 01, 2022
    )
  ),
  helpText(h5(strong("Output to table:"))),
  tableOutput("table1")
)

server <- function(input, output) {
  output$table1 <- renderTable({input$selected})
}

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