I am trying to create a conditional panel to display the editable/rhandsomtable table only when the value of validFile is 'FALSE". However, what I got to do is that every time the function returns, then the editable table is hidden. How could I express in the condition of the conditional panel that the rhandsomtable should only be displayed if the value returned by the function call in the server function -result$validFile- is FALSE?
library(shiny)
library(rhandsontable)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
column(width = 10,
conditionalPanel(
condition = "input.btn == true",
selectInput("value", label = h4("Do you have a params file ready to use (Y/N)?"),
choices = c("", "Y", "N"), selected = NULL)
),
conditionalPanel(
condition = "input.value == 'Y'",
helpText(h4("Select your params file")),
fluidRow(
column(width = 10, fileInput("file", "upload the file", accept = ".tsv", placeholder = "No file selected", multiple = FALSE))
)
# useShinyjs(), # Include shinyjs
# extendShinyjs(text = jscode, functions = c("closeWindow")),
#actionButton("close", "Stop glycoPipe")
)
)
),
mainPanel(
textOutput("invalidFile"),
conditionalPanel(
condition = "output.fileError",
helpText("Changes to the table will be automatically saved to the source file"),
actionButton("saveBtn", "Save"),
helpText("Handsontable demo output. Column add/delete does work ",
"for tables with defined column properties, including type."),
radioButtons("useType", "Use Data Types", c("TRUE", "FALSE")),
rHandsontableOutput("hot", width = 1500)
),
uiOutput("checkedFile")
)
)
)
glycoPipe <- function(inFileName){
list[valid, outL] <- extractParams(filename)
validFile = FALSE
invalidParamsFile <- "invalid params file"
list(valid = valid, outL = outL, validFile = validFile, invalidParamsFile = invalidParamsFile)
}
extractParams <- function(filename){
valid = "valid"
outL <- list(1,2,3,4,5)
return(list(valid, outL))
}
server <- function(input, output){
output$contents <- renderTable({
inFile = input$file
inFileName = input$file$name
if(is.null("inFile")){
return()
}
req(inFile)
validate( need(file_ext(inFile) %in% c(
'tsv'
), "Wrong File Format. The selected file is not a valid tab-separated PARAMS file try again. If
you do not have a parameters.tsv file in your directory stop clycoPipe create a file and re-start glycoPipe"))
read.delim(inFile$datapath, quote = "", sep = '\t')
})
output$checkedFile <- renderUI({
inFile <- input$file
inFileName <- input$file$name
result <- glycoPipe(inFileName)
result$outL
})
output$fileError <- reactive({
output$invalidFile <- renderText({
inFile <- input$file
inFileName <- input$file$name
result <- glycoPipe(inFileName)
if(result$validFile == FALSE)
result$invalidParamsFile
})
return(result$validFile)
})
outputOptions(output, "fileError", suspendWhenHidden = FALSE)
fname = tempfile(fileext = ".tsv")
observe({
input$saveBtn
hot = isolate(input$hot)
if (!is.null(hot)) {
write.table(hot_to_r(input$hot), fname)
print(fname)
}
})
output$hot = renderRHandsontable({
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
DF = read.delim( "~/Development/Rand/glycoPipe_PARAMS_TEMPLATE.tsv", sep = '\t', stringsAsFactors = FALSE)
}
rhandsontable(DF) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE)
})
values <- reactiveValues()
data = reactive({
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
if (is.null(values[["DF"]]))
DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10],
dt = seq(from = Sys.Date(), by = "days", length.out = 10),
stringsAsFactors = F)
else
DF = values[["DF"]]
DF = read.delim("~/Development/Rand/glycoPipe_PARAMS_TEMPLATE.tsv", sep = '\t', stringsAsFactors = FALSE)
}
values[["DF"]] = DF
DF
})
output$hot <- renderRHandsontable({
DF = data()
if (!is.null(DF))
rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all")
})
}
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents