And*_*rii 0 user-interface r button shiny dt
有一个选项可以在datatables.net网站上添加自定义按钮。如何在R Shiny应用中进行编码?一个按钮和观察者的基本R代码示例将非常有趣。
这是来自https://datatables.net/extensions/buttons/examples/initialisation/custom.html的 JS代码
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
text: 'My button',
action: function ( e, dt, node, config ) {
alert( 'Button activated' );
}
}
]
} );
} );
Run Code Online (Sandbox Code Playgroud)
谢谢 !
除了动作之外,您不需要使用Javascript。你可以做:
library(DT)
datatable(iris,
extensions = 'Buttons',
options = list(
dom = 'Bfrtip',
buttons = list(
"copy",
list(
extend = "collection",
text = 'test',
action = DT::JS("function ( e, dt, node, config ) {
alert( 'Button activated' );
}")
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
要将某些内容从Javascript传递到闪亮的服务器,请使用Shiny.setInputValue:
library(shiny)
library(DT)
ui <- basicPage(
DTOutput("dtable")
)
server <- function(input, output, session){
output$dtable <- renderDT(
datatable(iris,
extensions = 'Buttons',
options = list(
dom = 'Bfrtip',
buttons = list(
"copy",
list(
extend = "collection",
text = 'test',
action = DT::JS("function ( e, dt, node, config ) {
Shiny.setInputValue('test', true, {priority: 'event'});
}")
)
)
)
)
)
observeEvent(input$test, {
print("hello")
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)