How to use action buttons to show table output in Modal

Hi, I developed a shiny application to randomly select a single output on-click of the action button. How do I display the result as a modal pop-up? See my code below

library(styler)
library(shiny)
library(shinythemes)
library(shinydashboard)
library(tidyverse)
library(DT)
library(dplyr)
library(shinyBS)
#library(dt)

ui<-fluidPage(
  dashboardPage(skin="black",
                dashboardHeader(title=tags$em("Aura Promo", style="text-align:center;color:#ff8300;font-size:100%"),titleWidth = 800),
                
                dashboardSidebar(width = 270,
                                 sidebarMenu(
                                   #br(),
                                   menuItem(tags$em("Upload Data",style="font-size:120%"),icon=icon("upload"),tabName="data"),
                                   fileInput('datafile', 'Upload',
                                             accept=c('csv', 'comma-separated-values','.csv')),
                                   actionButton("update", "Select Winner", icon = icon("table"),
                                                class = "btn-default",style='padding:4px;font-size:100%')
                                   
                                
                                   
                                 )
                ),
                
                dashboardBody(
                  tabItems(
                    tabItem(tabName="data",
                            fluidRow(
                             # valueBoxOutput("Total"),
                              #valueBoxOutput("Gross"),
                              #valueBoxOutput("NoBypass")  
                            ),
                              br(),
                              br(),
                              br(),
                              
                              column(width = 4,
                                     tableOutput('table'),
                                     
                                     br(),
                                     br(),
                                     br(),
                              ),
                              
                              
                              # Output: Data file ----
                              tableOutput("contents") #DTOutput("contents")
                              
                            )))))
  
  server  <- function(input, output,session) {
    dataframe<-reactive({
      if (is.null(input$datafile))
        return(NULL)                
      data<-read.csv(input$datafile$datapath)
      data
    })
    
    #Generate random values
    observeEvent(input$update, {
      sampled_df <- reactive({
        test <- dataframe()[sample(nrow(dataframe()), 1), ]
        test
      })
      
      
      #Display Table on click
      output$table <- renderTable({
        sampled_df()
      })
    })
    
    # Display random output
    output$contents <- renderTable({
      dataframe()
    })
        
  }
  ## Run the application 
  shinyApp(ui = ui, server = server)

The documentation or creating modal dialogs with shiny is rather good I would say.
Have you read through it and tried the examples ?
Shiny - Create a modal dialog UI — modalDialog (rstudio.com)

Yes. Thanks... The modal works!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.