- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目标
replaceData()
以及 RDBMS (SQL Server) 上的数据。 Ohio
我想用 ID 2
设置我的数据(和 RDBMS) . replaceData()
replaceData()
library(shiny)
library(DT)
library(dplyr)
library(shinyjs)
library(DescTools)
# inspired by https://stackoverflow.com/questions/57215607/render-dropdown-for-single-column-in-dt-shiny/57218361#57218361
#
ui <- fluidPage(
useShinyjs(),
tags$head(tags$script(
HTML("
Shiny.addCustomMessageHandler('unbindDT', function(id) {
var $table = $('#'+id).find('table');
if($table.length > 0){
Shiny.unbindAll($table.DataTable().table().node());
}
})")
)),
title = 'Selectinput column in a table',
DT::dataTableOutput('foo_dt'),
verbatimTextOutput('selection'),
textInput("mypage",label = NULL,value ="" )
)
# in real case : Query on RDBMS SQL Server
df_product <- data.frame( Product = c(rep("Toaster", 3), rep("Radio", 3)),StateId = c(3,2,2,1,1,2), stringsAsFactors = FALSE)
df_state <- data.frame(StateId = c(1,2,3), State = c("Alabama","Ohio","WDC"), stringsAsFactors = FALSE)
df_datatable <- df_product %>% left_join(.,df_state, by = c("StateId"="StateId")) %>% select (Product,State,StateId)
myselected_vector <- (which(colnames(df_datatable) %in% c("StateId")) )
target_vector <- (which(colnames(df_datatable) %in% c("State")) )
df_state_select <-df_state %>% transmute (value=StateId,label=State) %>% unique()
list_label_value=setNames(df_state_select$value,df_state_select$label)
selectInputModel <-gsub("[\r\n]", "", as.character(
selectInput("selectionXX", "", choices = list_label_value, width = "100px")
))
server <- function(input, output, session) {
react <- reactiveValues(
foo_dt_page=NULL,
# in real case : Query on RDBMS SQL Server
datas = df_datatable,
foo_dt_refresh= FALSE
)
datas_react <-reactive({
input_evt=react$foo_dt_refresh
isolate(react$datas)
})
proxy_foo_dt=dataTableProxy('foo_dt')
output$foo_dt = DT::renderDataTable(
datas_react(), escape = FALSE, selection='single',
server = TRUE,
editable = list(target = "cell"),
options = list(
ordering = FALSE,
columnDefs = list(
list(orderable = FALSE, className = 'details-control', targets = target_vector),
list(width = '10px', targets = myselected_vector)
),
stateSave = TRUE,
pageLength = 2,
lengthMenu = c(2,5,6),
preDrawCallback = JS('function() {
Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS("function() {
mypage = $('#mypage').val();
if (typeof mypage !== 'undefined' && mypage.trim().length!=0) {
if ( $('#foo_dt').find('.dataTable').DataTable().page()!=parseInt(mypage) ) {
$('#foo_dt').find('.dataTable').DataTable().page(parseInt(mypage)).draw(false);
$('#mypage').val('');
}
}
Shiny.bindAll(this.api().table().node());
} ")
),
callback = JS(paste0("
table.on('click', 'td.details-control', function() {
console.log('phil test')
var td = $(this),
row = table.row(td.closest('tr'));
myrow = row.data()[0];
myselected = row.data()[",myselected_vector[1],"];
if ($('#selection' + myrow).length == 0) {
selectInputModel = '",selectInputModel[1],"';
selectInputModel = selectInputModel.replace('<select id=\\\"selectionXX\\\">','<select id=\\\"selectionXX\\\" class=\\\"shiny-bound-input\\\">');
selectInputModel = selectInputModel.replace(/XX/g, myrow);
// selectInputModel = selectInputModel.replace('selected', '');
selectInputModel = selectInputModel.replace('value=\\\"' + myselected + '\\\"', 'value=\\\"' + myselected + '\\\" selected');
td.html(selectInputModel);
Shiny.unbindAll(table.table().node());
Shiny.bindAll(table.table().node());
}
})
"))
)
output$selection = renderPrint({
str(sapply(1:nrow(datas_react()), function(i) input[[paste0("selection", i)]]))
})
ReplaceData_foo_dtRefresh <- function (react) {
react$foo_dt_refresh <- TRUE
session$sendCustomMessage("unbindDT", "foo_dt")
replaceData(proxy_foo_dt,(datas_react()) , resetPaging = TRUE)
react$foo_dt_refresh <- FALSE
}
observeEvent(lapply(1:nrow(isolate(datas_react())), function(i) input[[paste0("selection", i)]]), {
validate(
need(!is.null(input$foo_dt_cell_clicked) , message = FALSE)
)
print(
paste0(Sys.time() ," : ",
as.character( input$foo_dt_cell_clicked$row)," =" ,
input[[paste0("selection", input$foo_dt_cell_clicked$row )]]
)
)
if ( react$datas[input$foo_dt_cell_clicked$row,myselected_vector]!= input[[paste0("selection", input$foo_dt_cell_clicked$row )]] ) {
isolate(react$datas[input$foo_dt_cell_clicked$row,myselected_vector]<- input[[paste0("selection", input$foo_dt_cell_clicked$row )]] )
isolate(react$datas[input$foo_dt_cell_clicked$row,target_vector]<-(df_state %>% filter(StateId==input[[paste0("selection", input$foo_dt_cell_clicked$row )]]))$State)
ReplaceData_foo_dtRefresh (react)
updateTextInput(session,"mypage",label = NULL,ceiling(input$foo_dt_cell_clicked$row / input$foo_dt_state$length)-1)
}
},ignoreNULL = TRUE)
}
shinyApp(ui, server)
xfun::session_info()
Package version:
assertthat_0.2.1 backports_1.1.7 BH_1.72.0.3 callr_3.4.3 cli_2.0.2 colorspace_1.4.1 compiler_3.6.3 crayon_1.3.4
crosstalk_1.0.0 desc_1.2.0 digest_0.6.25 dplyr_1.0.0 DT_0.12.1 ellipsis_0.3.1 evaluate_0.14 fansi_0.4.1
farver_2.0.3 fastmap_1.0.1 generics_0.0.2 ggplot2_3.3.1 glue_1.4.1 graphics_3.6.3 grDevices_3.6.3 grid_3.6.3
gtable_0.3.0 htmltools_0.4.0 htmlwidgets_1.5.1 httpuv_1.5.2 isoband_0.2.1 jsonlite_1.6.1 labeling_0.3 later_1.0.0
lattice_0.20.38 lazyeval_0.2.2 lifecycle_0.2.0 magrittr_1.5 MASS_7.3.51.5 Matrix_1.2.17 methods_3.6.3 mgcv_1.8.31
mime_0.9 munsell_0.5.0 nlme_3.1.141 pillar_1.4.4 pkgbuild_1.0.8 pkgconfig_2.0.3 pkgload_1.1.0 praise_1.0.0
prettyunits_1.1.1 processx_3.4.2 promises_1.1.0 ps_1.3.3 purrr_0.3.4 R6_2.4.1 RColorBrewer_1.1.2 Rcpp_1.0.4.6
rlang_0.4.6 rprojroot_1.3.2 rstudioapi_0.11 scales_1.1.1 shiny_1.4.0 sourcetools_0.1.7 splines_3.6.3 stats_3.6.3
testthat_2.3.2 tibble_3.0.1 tidyselect_1.1.0 tools_3.6.3 utf8_1.1.4 utils_3.6.3 vctrs_0.3.1 viridisLite_0.3.0
withr_2.2.0 xfun_0.14 xtable_1.8-4 yaml_2.2.1
最佳答案
运行前必须解绑replaceData
.
ui <- fluidPage(
tags$head(tags$script(
HTML(
"Shiny.addCustomMessageHandler('unbindDT', function(id) {
var $table = $('#'+id).find('table');
if($table.length > 0){
Shiny.unbindAll($table.DataTable().table().node());
}
})")
)),
title = 'Selectinput column in a table',
......
并在
server
:
......
session$sendCustomMessage("unbindDT", "foo_dt")
ReplaceData_foo_dtRefresh (react)
关于jquery - 渲染 DT 中单列的下拉列表 Shiny 但仅在单元格单击时加载并使用 replaceData(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63073557/
我有一个针对单行中的单个列的mysql查询 "SELECT some_col_name FROM table_name WHERE user=:user" 执行语句$stmt->execute();后
我想创建一个应用程序,以这种格式在核心文本(滑动到下一页)中显示捆绑文本文件: 旁遮普语文本 旁遮普语音译成英语 旁遮普语翻译成英语 但我希望用户能够通过设置选项卡选择显示的语言,我知道该怎么做,即
我已经在 Angular 应用程序中设置了一个 ag-grid。我正在尝试使单列填充网格的整个宽度。 但后来我明白了。
当我在 excel 中打开我的 csv 文件时,它看起来像这样 - header 值 1值2值3值4值5 我想知道这个文件中是否真的有逗号?我知道如果我有多个列,我会看到逗号 最佳答案 您可以通过在文
我目前正在运行如下查询: SELECT a.ID, a.ContactID, a.Code, FROM tableA a JOIN (SELECT ContactID, Code FROM
当我在 excel 中打开我的 csv 文件时,它看起来像这样 - header 值 1值2值3值4值5 我想知道这个文件中是否真的有逗号?我知道如果我有多个列,我会看到逗号 最佳答案 您可以通过在文
我正在使用 codeigniter insert_batch($table, $data);我的列名称为“客户发布的评论”。 当我尝试批量插入数据时。插入查询更改为: INSERT INTO `tab
我有两个问题: 我想知道这是否是对单列 TreeView 进行搜索/过滤的正确方法。我觉得我的很多复制/粘贴可能包含不必要的东西。 QSortFilterProxyModel子类中的所有代码和sear
我有一个应用程序,我想获取多个软件包的 RPM 信息,并以令人愉悦且引人注目的方式对其进行格式化。 *繁荣*。 我的问题是 rpm 想要将数据格式化为两列,这很烦人。 命令 rpm -qi ruby
具有单列表(身份列)的目的是什么?有没有好的用例可用? 这真的是一个好习惯吗? 最佳答案 我认为人们使用它来复制 Oracle 的 SEQUENCE。基本上,他们希望他们在系统中创建的任何实体都有一个
我正在将数据库连接从 mysqli 转移到 PDO。更新时,我陷入了一个查询:在mysql中它是: $quec='designation=10 OR designation=11 OR designa
给定MySQL中的一列字符串(密码)并给定一个值N,我正在寻找一种sql方式来计算每个n-的频率gram(长度为 n 的子串)。 将代码保留在 MySQL 中很重要,因为在我拥有的其他环境中,它会导致
我对 GtkTreeView 有以下问题。 当我尝试附加列表时出现问题。这是我创建的函数: static GtkWidget *setup_list_archive(GtkWidget **wid
我是 JPA/Hibernate 的新手。假设我有这两个表: Employee (Id, Name, DeptId, ..)//DeptId 是外键。 Department (Id, DeptName
我正在调用的 REST API 返回一个数组,格式如下: ["a", "b", "c", "d"] 我的 ui-grid 需要在单列中显示这些数据条目,每行一个。 我有: $scope.items
我正在使用由 passy 创建的 Angular masonry 指令,当第一个元素的宽度几乎达到 100% 时我遇到了问题。在这种情况下,所有元素都合并在一个列中,否则我认为行为没问题。 我创建了一
我想将此嵌套数组转换为单个 pandas 数据框列,我该怎么做?有人可以帮我吗? array([array([ nan, 16.40411828, 23.671878
有一个遗留的 LAMP 应用程序,我正在将其转换为 JVM。 所讨论的问题需要一个包含@250K 记录的评分表。目前,“scoreType”列表示为tinyint,其中1 = 目标,2 = 协助1,3
我正在考虑 MySQL 5.6 InnoDB 表的以下架构。我无法决定使用哪些键: "CREATE TABLE IF NOT EXISTS `context` (" " `text_
我是一名优秀的程序员,十分优秀!