首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RHandsontable - renderUI映射

RHandsontable - renderUI映射
EN

Stack Overflow用户
提问于 2022-05-25 19:46:06
回答 1查看 56关注 0票数 0

我想在有动态切片的数据集中,按切片因子显示一个HoT表。下面是我实现这一目标的最佳尝试,但输出是一个复制表。从打印出的拆分数据帧中可以看出一切看起来如何正确,但RHandsontable似乎存在一个问题,即它只指向映射中创建的最后一个HoT。

知道如何实现显示不同的数据格式吗?

代码语言:javascript
复制
library(shiny)
library(dplyr)
library(rhandsontable)
library(purrr)
ui <- fluidPage(

  uiOutput('tables')
)

server <- function(input, output) {
  mtcars$slc <- sample(c('aaa','bbb'),nrow(mtcars),replace=TRUE)
  df <- mtcars
  
  getSlice <- function(df_tmp,slca){
    print(slca)
    df_tmp <- df_tmp %>% filter(slc==slca)
    df_tmp
  }
  
  output$tables <- renderUI({
    slices <- unique(df$slc)
    input_dfs <- map(slices,~getSlice(df,.x))
    
    for(i in 1:length(slices)){
      print(input_dfs[[i]]) # proof that there are two distinct data 
                            #  frames going into renderRHandsontable()
      output[[slices[i]]] <- renderRHandsontable(rhandsontable(input_dfs[[i]]))
    }
    
    out <- map(slices,function(x){
      rHandsontableOutput(x)
    })
    print(out) # div ids are correctly distinct, but the tables that show are not!
    out
  })
}

shinyApp(ui = ui, server = server)

输出-所有'aaa‘副本.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-26 02:32:25

在for循环中使用local()

代码语言:javascript
复制
for(i in 1:length(slices)){
  local({
    i <- i
    print(input_dfs[[i]]) # proof that there are two distinct data 
    #  frames going into renderRHandsontable()
    output[[slices[i]]] <- renderRHandsontable(rhandsontable(input_dfs[[i]]))
  })
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72383374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档