我想默认显示一个数据表,其中包含数据框中的一列,然后让用户使用可排序的拖放包从数据框中填充其他列。
通过一个文件闪亮的应用程序运行时,我在这里有一个工作示例。
library(shiny)
library(sortable)
library(DT)
a <- c("13232","24343","A434535")
b <- c("fsf","dfgds","ggdf")
c <- c("13232","24343","A434535")
d <- c("fsf","dfgds","ggdf")
data <- data.frame(a,b,c,d)
ui <- fluidPage(
tags$head(
tags$style(HTML(".bucket-list-container {min-height: 350px;}"))
),
fluidRow(
tags$b("Data Table"),
width = 12,
bucket_list(
header = "Drag the items in any desired bucket",
group_name = "bucket_list_group",
orientation = "horizontal",
add_rank_list(
text = " Specific Variables",
labels = colnames(data),
input_id = "rank_list_1"
),
add_rank_list(
text = "Contents Of Data Table",
labels = NULL,
input_id = "rank_list_2"
))
),
fluidRow(
column(
width = 12,
tags$b("Result"),
column(
width = 12,
tags$p("Table"),
DTOutput('tbl')
)
)
)
)
server <- function(input,output) {
output$tbl = renderDT(cbind(data[1],data[,c(input$rank_list_2)]), options = list(lengthChange = FALSE)
)
}
shinyApp(ui, server)
虽然这工作正常。当我尝试以模块化格式实现这一点时,数据表无法更新。
用户界面
sort_ui <- function(id) {
ns <- NS(id)
tagList(
tabsetPanel(
tabPanel("Data Table",
fluidRow(
tags$b("Data Table"),
width = 12,
bucket_list(
header = "Drag the items in any desired bucket",
group_name = "bucket_list_group",
orientation = "horizontal",
add_rank_list(
text = "Contents Of Data Table",
labels = NULL,
input_id = "rank_list_1"
))
),
add_rank_list(
text = "Contents Of Data Table",
labels = NULL,
input_id = "rank_list_2"
))
),
fluidRow(
column(
width = 12,
tags$p("Table"),
DT::dataTableOutput(ns('table'))
)
)
)
服务器
sort_server <- function(input, output, session,globalSession){
ns <- session$ns
a <- c("13232","24343","A434535")
b <- c("fsf","dfgds","ggdf")
c <- c("13232","24343","A434535")
d <- c("fsf","dfgds","ggdf")
data <- data.frame(a,b,c,d)
x <- data[1]
data <- reactive(cbind(x,ihc[,c(input$rank_list_2)]))
output$table = DT::renderDataTable(data(), options = list(stateSave = TRUE)
)
proxy <- dataTableProxy('table', session = globalSession)
}
我用
callModule(sort_server,"my_sort_module",globalSession = session)
不知道我在这里做错了什么。