从textSearch到Shiny中的Handsontable搜索 [英] Search from a textInput to a Handsontable in Shiny

查看:129
本文介绍了从textSearch到Shiny中的Handsontable搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Shiny中与Handsontable合作已经有好几天了,我陷入了一个非常愚蠢的问题,但我不太想知道如何解决.

I've been working for some days with Handsontable in Shiny and I got stuck in what I guess will be a very dumb question but I have not this much idea how to solve.

我有一个Handsontable,它具有一个允许搜索的自定义功能,并且可以工作.它可以工作,但不够直观,因为您必须右键单击表格以弹出搜索选项.

I have a Handsontable that has a custom function that allows searching and it works. It works but is not intuitive enough because you have to right-click on the table to pop the search option.

因此,我决定要一个textInput来执行相同的功能,但是要更漂亮.我知道它应该与输入变量(input $ searchId)的watchEvent有关,但是由于我对Shiny和Handsontable缺乏经验,所以我不知道该怎么做.

Because of this, I decided that I would like to have a textInput that does the same function but in a prettier way. I know that it should be related with an observeEvent of the input variable (input$searchId) but I have no idea of how to do it due to my lack of experience with Shiny and Handsontable.

这是来自server.R的代码,该代码打印表并具有允许用户搜索的自定义功能.

This is the code from server.R that prints the table and that has a custom function that allows the user to search.

output$hot <-renderRHandsontable({rhandsontable(Dataset(),height = 600)%>%   
hot_table( columnSorting = TRUE,highlightCol = TRUE, highlightRow = TRUE, search = TRUE) %>% 
hot_context_menu(
  customOpts = list(
    search = list(name = "Search",
                  callback = htmlwidgets::JS(
                    "function (key, options) {
                     var aux = document.getElementById('searchId').value;
                     var srch = prompt(Search);

                     this.search.query(srch);
                     this.render();
                   }")))) })

我想要的是存档相同的结果,但是不必右键单击表并创建提示.

And what I would like is to archive the same result but without having to right-click on the table and create a prompt.

非常感谢您,

推荐答案

好,我已经能够解决我的问题.我的灵感来自这篇文章 然后我得到了类似的东西:

Well I've been able to solve my problem. I've been inspired by this post and then I got with something like:

js_search <- "
$(document).ready(setTimeout(function() {
  document.getElementById('searchId').onchange = function(e){
    var hot_instance = HTMLWidgets.getInstance(hot).hot
    console.log('hola')
    var aux = document.getElementById('searchId').value;
    hot_instance.search.query(aux);
    hot_instance.render();
  }
}))
"

必须用tags$head(tags$script(HTML(js_search)))

这就是我所面临的全部问题,我不知道如何从以前在服务器端的自定义操作中获取"this".一旦知道了那是hot_instance.我的桌子的名字在哪里很热,我认为很容易.

That's all the problem I was having is that I ahd no idea of how to get the "this" from the custom operation in the server side I had before. Once you know that is hot_instance. where hot is the name of my table, I think is easy.

这篇关于从textSearch到Shiny中的Handsontable搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆