How to take and display an cellvalue in Shiny?

Hi all

I upload a file to the Shiny, this is a file with always the same format, so the date of the extracted data is always in the same cell.
image

As an extra control, I want to display the date after the file is uploaded, but I don't get it and I don't get an error.

This is the UI code of that section:

sidebarLayout(
                           sidebarPanel(
                             fileInput("import", "Choose TXT/CSV File", accept = c("text/csv",
                                                                                   "text/comma-separated-values,text/plain",
                                                                                   ".csv")),
                             p("The data of the datafile is:"),
                             verbatimTextOutput("output$date"),
                             p("Please ...
                           )

This is the server part of that section:

server = shinyServer(function(input, output,session){
  
  
  observeEvent(input$import, {
    file1 <- input$import
    server_data <- read.delim(file=file1$datapath, header = TRUE, na.strings=c(""," ","NA"))
    #Create a subset of the data to remove/exclude the unnecessary columns:
    subset_data_server <- server_data[,c(-5,-7,-9,-17,-25:-31)]
    #Remove the rows with blank/NA values:
    df1 <- na.omit(subset_data_server)
    #The difference between the ResultTime and the FirstScanTime is the turn around time:
    df1$TS_start <- paste(df1$FirstScanDate, df1$FirstScanTime)
    df1$TS_end <- paste(df1$ResultDate, df1$ResultTime)
    df1$TAT <- difftime(df1$TS_end,df1$TS_start,units = "mins")
    
    output$date <- renderText({ 
      as.character(server_data[2, server_data$FirstScanDate])
      })

...

The output$date is in the "obserEvent()" function, so it should be calculated after a file is uploaded.

Can you help me?

Thank you!

I think you need to reflect on the relationship between UI element ID's and how they are accessed on the server side. When you want to have a output$name <-render* in the server side the accompanying placeholder on the UI side should be called simply name and not output$name

To make this explicit, I will show a working app where the UI object is named 'output$date', this should be understood as a clumsy approach and the preferred app is posted after .

library(shiny)

ui <- fluidPage(
  verbatimTextOutput("output$date")
)

server <- function(input, output, session) {
  output$`output$date` <- renderText("We have rendered text")
}

shinyApp(ui, server)

again but better


library(shiny)

ui <- fluidPage(
  verbatimTextOutput("date")
)

server <- function(input, output, session) {
  output$date <- renderText("We have rendered text")
}

shinyApp(ui, server)

Hi

Thank you, I also needed to remove the curled brackets in the server. Both stupid mistakes.

Kind regards

This topic was automatically closed 7 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.