1

I have a beginner problem. I need to turn columns into checkbox. Next, I need to assign integer values ​​to these checkbox (1,2,3) so that they are transported to the function "int<-csv()[,c(5,6,7,8,9,10)]" (where the numeric values ​​are separated by commas). Also, I need that if more than one item is selected, a comma is placed to the right of it. It is possible? Thanks in advance!

This is my code:

library(shiny)
library(shinydashboard)
library(shinyWidgets)

library(readxl)
library(tidyverse)
library(readxl)
library(stringr)


# Dashboard

ui <- dashboardPage(
                    
                    dashboardHeader(
                        title = "Page"
                    ),
                    
                    dashboardSidebar(
                        sidebarMenu(
                            
                            menuItem(
                                "Home",
                                tabName = "home")
                        )
                    ),
                    
                    dashboardBody(
                        
                        tabItems(
                            
                            # Home  
                            
                            tabItem(
                                tabName = "home", h2("Hello!"),
                                
                                br(),
                                
                                box(
                                    width = 100,
                                    fileInput("file", "Choose the Sheet", accept = c(
                                        ".xlsx")),
                                ),
                                
                                p("Upload Sheet", style="font-weight: bold;"),
                                
                                box(
                                    width = 200,
                                    tableOutput("content"), style="overflow: 
                                hidden; height: 90px; overflow-y: scroll; 
                                overflow-x: scroll;")
                            )
                        ),
                    )
)
                            

# Server

server <- function(input, output, session) {
    
    
    # Sheet Upload
    
    csv <- reactive({
        req(input$file)
        inFile <- input$file
        df<- read_xlsx(inFile$datapath)
        return(df)
    })
    
    # Archive Without Extension
    
    output$my_file <- renderText({
        # Test if file is selected
        if (!is.null(input$file)) {
            return(str_replace(input$file$name, '\\.xlsx', ' ') )
        } else {
            return(NULL)
        }
    })
    
    # Show Datasheet
    
    output$content <- renderTable({
        
        req(input$file)
        inFile <- input$file
        read_excel(inFile$datapath, sheet = 1, col_names = TRUE, 
                   col_types = NULL, na = "", skip = 0)
    })
    
    output$calfa <-
        renderPrint({
            int<-csv()[,c(5,6,7,8,9,10)]
            names(int)
        })
    
}   

# App

shinyApp(ui = ui, server = server)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
JVicM
  • 67
  • 4
  • 1
    You can add a checkbox to datatable , see here https://stackoverflow.com/questions/26026740/rstudio-shiny-list-from-checking-rows-in-datatables . also the same post shows how you can get the index of rows selected. – Ronak Shah Jun 17 '21 at 04:05

0 Answers0