1

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

Adam Shaw
  • 519
  • 9
  • 24
  • 1
    Possible duplicate of [How to place buttons in Shiny](https://stackoverflow.com/questions/40537917/how-to-place-buttons-in-shiny) – Roberto Moratore Apr 09 '18 at 11:42
  • @RobertoMoratore, Very different question that one. here above all I need is to position the button a little below, I don't see a good css attribute there. Please help. – Adam Shaw Apr 09 '18 at 11:50
  • 1
    You cannot put a button inside the DT table. – J0ki Apr 09 '18 at 12:15
  • @J0ki, Thanks for the reply, but atleast can't we shift the button down a bit? – Adam Shaw Apr 09 '18 at 12:16
  • I don't think so because a little below is the div of the DT table, maybe think to put it below the table. – J0ki Apr 09 '18 at 12:17
  • @J0ki, please check the link here, if you can help me https://rstudio.github.io/DT/003-tabletools-buttons.html – Adam Shaw Apr 10 '18 at 08:16
  • Then u can put the button like this link but don't know how to add html to center it. – J0ki Apr 10 '18 at 08:25
  • @J0ki, can you help me with the script, as I am not able to do it. – Adam Shaw Apr 10 '18 at 08:58
  • Use the example, quit your DT::datatable, and use only datatable(iris, ....) do the same that the example but change the button name to your s. – J0ki Apr 10 '18 at 09:23

1 Answers1

3

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

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225