jeudi 17 juin 2021

R/Shiny - Transfer checkbox labels to function field

I need the selected checkbox labels to fill in the "[,c("checkbox1","checkbox2")]" field (where both "checkbox1" and "checkbox2" are written). Thank you.

This is my code.

library(shiny) library(shinydashboard) library(shinyWidgets) library(readxl) library(tidyverse) library(readxl) library(stringr)

ui <- fluidPage(

br(),

fileInput("archive", "Upload file", accept = c(
    ".xlsx")),

    # Itens Selection
checkboxGroupInput("additem", "Select Items", choices = NULL)
    )
box(
    width = 2000,
    verbatimTextOutput("calfa")

)

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

    # Upload Data Sheet

csv <- reactive({
    req(input$archive)
    inFile <- input$archive
    df <- read_xlsx(inFile$datapath)
    return(df)
})

    #reactive value that will hold the name of the file
reactive_my_path <- reactive({
    # Test if file is selected
    req(input$archive)
    return(sub(".xlsx$", "", basename(input$archive$name)))
})

observe({
    input$archive
    # update the choices in input$additem
    updateCheckboxGroupButtons(session,
                               "additem",
                               paste('Column names in:', reactive_my_path()),
                               choices = names(csv()))
})

    # Alpha
output$calfa <-
    renderPrint({
        int<-csv()[,c("checkbox1","checkbox2")]
        int <- na.omit(int) 
        psych::alpha(int, check.keys = TRUE) 
    })

}

App

shinyApp(ui, server)




Aucun commentaire:

Enregistrer un commentaire