将常规按钮添加到数据表 - 闪亮的应用程序
adding regular button to datatable - shiny app
我在闪亮的应用程序中使用数据表。
我想在搜索按钮附近添加一个按钮。
当我点击我想调用函数的按钮时:observeEvent(input[["btn"]]
这是我的代码:
DT::renderDataTable(rownames = FALSE,
DT::datatable(my_df,extensions = 'Buttons',
options = list(info = FALSE, paging = FALSE,
dom='Bfrtip', buttons= list('copy')
)))
它看起来不错,但我想要一个普通按钮来调用而不是复制按钮
这个函数:observeEvent(输入[["btn"]]
知道我该怎么做吗?
让我们定义一个自定义按钮。
通过 text
更改按钮标签,更改 setInputValue
中闪亮的输入 ID,将 mydf_btn
更改为您想要的任何内容。
library(shiny)
ui <- fluidPage(
DT::DTOutput("mydf")
)
server <- function(input, output, session) {
output$mydf <- DT::renderDataTable(
DT::datatable(
iris,extensions = 'Buttons', rownames = FALSE,
options = list(
info = FALSE, paging = FALSE, dom='lfBrtip',
buttons= list(
list(
extend = 'collection',
text = 'My Action',
action = DT::JS(
"function() {
var node = this[0].node;
var value = $(node).attr('data-value') || 0;
value ++;
$(node).attr('data-value', value);
Shiny.setInputValue('mydf_btn', value, {priority: 'event'});
}"
)
)
)
)
)
)
observe(print(input$mydf_btn))
}
shinyApp(ui, server)
我在闪亮的应用程序中使用数据表。 我想在搜索按钮附近添加一个按钮。 当我点击我想调用函数的按钮时:observeEvent(input[["btn"]] 这是我的代码:
DT::renderDataTable(rownames = FALSE,
DT::datatable(my_df,extensions = 'Buttons',
options = list(info = FALSE, paging = FALSE,
dom='Bfrtip', buttons= list('copy')
)))
它看起来不错,但我想要一个普通按钮来调用而不是复制按钮 这个函数:observeEvent(输入[["btn"]] 知道我该怎么做吗?
让我们定义一个自定义按钮。
通过 text
更改按钮标签,更改 setInputValue
中闪亮的输入 ID,将 mydf_btn
更改为您想要的任何内容。
library(shiny)
ui <- fluidPage(
DT::DTOutput("mydf")
)
server <- function(input, output, session) {
output$mydf <- DT::renderDataTable(
DT::datatable(
iris,extensions = 'Buttons', rownames = FALSE,
options = list(
info = FALSE, paging = FALSE, dom='lfBrtip',
buttons= list(
list(
extend = 'collection',
text = 'My Action',
action = DT::JS(
"function() {
var node = this[0].node;
var value = $(node).attr('data-value') || 0;
value ++;
$(node).attr('data-value', value);
Shiny.setInputValue('mydf_btn', value, {priority: 'event'});
}"
)
)
)
)
)
)
observe(print(input$mydf_btn))
}
shinyApp(ui, server)