2017-09-18 20 views
1

我一直在使用Handsontable在閃亮的一些日子裏工作,我被困在我猜想會是一個非常愚蠢的問題,但我沒有這麼多想法如何解決。從textInput搜索到一個Handsontable在閃亮

我有一個Handsontable有一個自定義函數,允許搜索和它的工作。它可以工作,但不夠直觀,因爲您必須右鍵單擊表格以彈出搜索選項。

正因爲如此,我決定我想有一個textInput,但以一種更漂亮的方式執行相同的功能。我知道它應該與輸入變量的觀察事件(輸入$ searchId)有關,但由於缺乏Shiny和Handsontable的經驗,我不知道該怎麼做。

這是server.R中的代碼,它打印表並且具有允許用戶搜索的自定義函數。

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(); 
        }")))) }) 

而我想要的是歸檔相同的結果,但不必右鍵單擊表並創建提示。

太感謝你了,

回答

0

嗯,我已經能夠解決我的問題。我一直this post 靈感,然後我喜歡的東西了:

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)))

這就是我遇到的問題你ui.R是我不知道如何從我之前的服務器端的自定義操作中獲取「this」。一旦你知道這是hot_instance。哪裏熱是我桌子的名字,我覺得很容易。