Multiple buttons in DataTable calling the same modalDialog - Shiny
up vote
1
down vote
favorite
I am creating a dashboard with shiny that contains a datatable. In this Datatable I created a column which contains buttons having all the same id 'inf'
(using columnDefs's options) and I handled buttons event using onclick()
to open a specific modalDialog (code below). The problem is that since all my buttons have the same id, the onclick
function works only in one button (see the Demo). So how can I make all the buttons open a same modalDialog ? Or how can I attribute a different ids for the buttons ?
server.R
df = mtcars
df$Description = NA
df = df[,c(12,1,2,3,4,5,6,7,8,9,10,11)]
output$table <- DT::renderDataTable(
df,
options = list( paging = FALSE, scrollY = 354,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': 'white', 'color': 'black', 'font-weight' : 'bold'});",
"}"),
columnDefs = list(
list(className = 'dt-center',
targets = 1,
data = NULL,
defaultContent = "<button id='inf' type='button' class='btn btn-default action-button shiny-bound-input'><i class= 'fa fa-question-circle'/></button>"
)
)
),
selection = 'single',
style = 'bootstrap'
)
onclick("inf",{
showModal(
modalDialog( h4(input$table_rows_selected))
)
})
r button datatable shiny
add a comment |
up vote
1
down vote
favorite
I am creating a dashboard with shiny that contains a datatable. In this Datatable I created a column which contains buttons having all the same id 'inf'
(using columnDefs's options) and I handled buttons event using onclick()
to open a specific modalDialog (code below). The problem is that since all my buttons have the same id, the onclick
function works only in one button (see the Demo). So how can I make all the buttons open a same modalDialog ? Or how can I attribute a different ids for the buttons ?
server.R
df = mtcars
df$Description = NA
df = df[,c(12,1,2,3,4,5,6,7,8,9,10,11)]
output$table <- DT::renderDataTable(
df,
options = list( paging = FALSE, scrollY = 354,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': 'white', 'color': 'black', 'font-weight' : 'bold'});",
"}"),
columnDefs = list(
list(className = 'dt-center',
targets = 1,
data = NULL,
defaultContent = "<button id='inf' type='button' class='btn btn-default action-button shiny-bound-input'><i class= 'fa fa-question-circle'/></button>"
)
)
),
selection = 'single',
style = 'bootstrap'
)
onclick("inf",{
showModal(
modalDialog( h4(input$table_rows_selected))
)
})
r button datatable shiny
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am creating a dashboard with shiny that contains a datatable. In this Datatable I created a column which contains buttons having all the same id 'inf'
(using columnDefs's options) and I handled buttons event using onclick()
to open a specific modalDialog (code below). The problem is that since all my buttons have the same id, the onclick
function works only in one button (see the Demo). So how can I make all the buttons open a same modalDialog ? Or how can I attribute a different ids for the buttons ?
server.R
df = mtcars
df$Description = NA
df = df[,c(12,1,2,3,4,5,6,7,8,9,10,11)]
output$table <- DT::renderDataTable(
df,
options = list( paging = FALSE, scrollY = 354,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': 'white', 'color': 'black', 'font-weight' : 'bold'});",
"}"),
columnDefs = list(
list(className = 'dt-center',
targets = 1,
data = NULL,
defaultContent = "<button id='inf' type='button' class='btn btn-default action-button shiny-bound-input'><i class= 'fa fa-question-circle'/></button>"
)
)
),
selection = 'single',
style = 'bootstrap'
)
onclick("inf",{
showModal(
modalDialog( h4(input$table_rows_selected))
)
})
r button datatable shiny
I am creating a dashboard with shiny that contains a datatable. In this Datatable I created a column which contains buttons having all the same id 'inf'
(using columnDefs's options) and I handled buttons event using onclick()
to open a specific modalDialog (code below). The problem is that since all my buttons have the same id, the onclick
function works only in one button (see the Demo). So how can I make all the buttons open a same modalDialog ? Or how can I attribute a different ids for the buttons ?
server.R
df = mtcars
df$Description = NA
df = df[,c(12,1,2,3,4,5,6,7,8,9,10,11)]
output$table <- DT::renderDataTable(
df,
options = list( paging = FALSE, scrollY = 354,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': 'white', 'color': 'black', 'font-weight' : 'bold'});",
"}"),
columnDefs = list(
list(className = 'dt-center',
targets = 1,
data = NULL,
defaultContent = "<button id='inf' type='button' class='btn btn-default action-button shiny-bound-input'><i class= 'fa fa-question-circle'/></button>"
)
)
),
selection = 'single',
style = 'bootstrap'
)
onclick("inf",{
showModal(
modalDialog( h4(input$table_rows_selected))
)
})
r button datatable shiny
r button datatable shiny
edited Nov 22 at 16:14
asked Nov 22 at 16:03
BKenz
83
83
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434665%2fmultiple-buttons-in-datatable-calling-the-same-modaldialog-shiny%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown