Hello Guys,
I am new in Shiny app. As per my requirements, I have tried hard to work on codes to achieve the requirements. But, still, at some point, I am facing difficulties. I will be grateful to you if you could kindly help me out. Please find the codes at below, I apologize for messy codes.
My current difficulties are:
(1) I am able to see all the variables (of selected .csv file) in rhandsontable, but I am unable to select more than one variable at a time. I would like to select multiple variables at the same time and also one checkbox for all variable selection (like select all variables).
(2) I would like to add elementary statistical information of the selected column on the second page of dashboardBody.
I am looking forward to your positive response.
library(shiny)
library(shinydashboard)
library(rhandsontable)
ui = dashboardPage(
dashboardHeader(title = "Assignment"),
dashboardSidebar(
sidebarMenu(
menuItem("Laboratory", tabName = "Laboratory", icon = icon("dashboard"))
)
),
dashboardBody(
fluidRow(
selectInput(
"select2", label = h3("Select Year"), selected = "lab2018.csv",
choices = list("lab2016.csv", "lab2017.csv", "lab2018.csv")),
radioButtons("disp", "Display",
choices = c(All = "all",
Tail = "tail"),
selected = "all"),
uiOutput("checkbox")
),
fluidRow(actionButton("saveBtn", "Save changes"),
downloadButton("downloadData", "Download", style = "position:absolute;right:0;")
),
fluidRow(
box(rHandsontableOutput("hot"), width = 13, height = 408)
)
)
)
server <- function(input, output, session) {
DF <- reactiveVal()
observe({
DF(read.csv(input$select2, stringsAsFactors = FALSE))
})
observe({
if (!is.null(input$hot)) DF(hot_to_r(input$hot))
})
observeEvent(input$saveBtn, {
if (!is.null(DF())) write.csv(DF(), input$select2, row.names = FALSE)
})
output$hot <- renderRHandsontable({
rhandsontable(
if(input$disp == "tail") {
tail(df_sel())
}
else {
df_sel()
})
})
output$downloadData <- downloadHandler(
filename = function(){
paste(input$select2, input$filetype, sep = "")
},
content = function(file){
write.csv(DF(), file)
}
)
output$checkbox <- renderUI({
checkboxGroupInput(inputId = "select_var",
label = "Select variables",
choices = names(DF()), inline = TRUE)
})
output$hot <- renderRHandsontable({
rhandsontable(df_sel(), width = "100%", height = 390) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE, readOnly = FALSE, selectCallback = TRUE) #%>%
#hot_col("Status", readOnly = FALSE)
})
}
shinyApp(ui, server)