How can I reactively add actionButtons to the tableOutput?

0 votes
library(shiny)
# ui ##########################
ui <- fluidPage(
   fileInput("csv", label="",
      multiple = TRUE,
      accept = c("text/csv", ".csv")),
   tags$hr(),
   actionButton("show.tbl", "SHOW TABLE"),
   tableOutput("my_tbl")
   )
# server #########################
server <- function(input, output) {
   tbl <- data.frame(Example = LETTERS[1:10]) # will be reactive in reality
   output$my_tbl <- renderTable({
      if(input$show.tbl == 1)
         tbl
    })
 }
# app ######################
shinyApp(ui, server)

How can I reactively add actionButtons to the tableOutput?

Dec 5, 2018 in Data Analytics by Ali
• 10,450 points
38 views

1 answer to this question.

0 votes

Use DT for this purpose:

library(shiny)
library(DT)

ui <- fluidPage(
    verbatimTextOutput(outputId = 'vb'),
    dataTableOutput(outputId = 'table')
)

server <- function(input, output, session) {

    yourData <- reactive({
        return(mtcars)
    })

    output$vb <- renderPrint({
        req(input$table_rows_selected, cancelOutput = TRUE)
        row_id <- input$table_rows_selected

        row_selected <- yourData()[row_id,]

        return(row_selected)
    })

    output$table <- renderDataTable({

        datatable(
            data = yourData(),
            selection = 'single'
        )
    })
}

shinyApp(ui, server)
answered Dec 5, 2018 by Maverick
• 10,040 points

Related Questions In Data Analytics

0 votes
1 answer

How can I import a file in R without giving the destination/file path to the specified file?

You can use the window explorer to ...READ MORE

answered Aug 28, 2018 in Data Analytics by ANMOL
• 3,620 points

edited Aug 28, 2018 by Vardhan 33 views
0 votes
1 answer
0 votes
1 answer

How can I use parallel so that it preserves the list of data frames

You can use pmap as follows: nc <- ...READ MORE

answered Apr 4, 2018 in Data Analytics by kappa3010
• 2,010 points
24 views
0 votes
1 answer

Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

answered Apr 17, 2018 in Data Analytics by anonymous
924 views
0 votes
1 answer

Error saying "could not find function "shinyUI"" in shiny R

Its a small spelling mistake that you've ...READ MORE

answered Nov 28, 2018 in Data Analytics by Maverick
• 10,040 points
311 views
0 votes
1 answer

Error saying "could not find function dashboardPage" in shiny R

Include this line in the code: Library(shinydashboard) READ MORE

answered Nov 28, 2018 in Data Analytics by Maverick
• 10,040 points
169 views
0 votes
1 answer

How do I copy an excel file to my Rconsole with all the missing values?

You can use read.table function in the ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,040 points
28 views
0 votes
1 answer

How do I add Icons to my messages on my dashboard which I’m creating using shiny r?

Try something like this: dashboardHeader(title="Edureka", dropdownMenu type = "message", messageItem(from = ...READ MORE

answered Nov 29, 2018 in Data Analytics by Maverick
• 10,040 points
47 views