Adam Shaw
Adam Shaw

Reputation: 519

Adjust the position of actionButton widget in R shiny DT table

The given R shiny script creates a simple data table as in the snapshot with an actionButton in the center. I want to place the button a little below it's current position such that it is in perfect horizontal inline position to the search bar. Thanks and please help.

library(DT)
library(shiny)
library(shinyBS)
library(rpivotTable)
library(bupaR)
ui <- basicPage(
h2("The mtcars data"),
column(5,offset = 5,actionButton("CR1_S1", "Button")),
dataTableOutput("mytable1")
)
server <- function(input, output) {
output$mytable1 <- DT::renderDataTable({
DT::datatable(iris)
})
}
shinyApp(ui, server)

Data Snapshot

Upvotes: 1

Views: 2403

Answers (1)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84529

You can put the button inside the datatable in this way:

ui <- basicPage(
  h2("The mtcars data"),
  actionButton("CR1_S1", "Button"),
  DTOutput("mytable1")
)
server <- function(input, output) {
  output$mytable1 <- renderDT({
    datatable(iris, callback = JS("$('div.button').append($('#CR1_S1'));"), 
              options = list(
                dom = '<"row"<"col-sm-4"l><"col-sm-4 text-center"<"button">><"col-sm-4"f>>tip'
              ))
  })
}
shinyApp(ui, server)

enter image description here

Upvotes: 3

Related Questions