0

When I call a file inside the tabPanel, it comes with the TRUE value and I can't remove it, I've tried several ways with several examples, but without success. I'm working directly on the file that calls another file.

library(shiny)

library(shinythemes)

ui <- fluidPage(
  theme = shinytheme("flatly"),
  navbarPage(
    "Admission System",
    tabPanel(
      "Recruitment and selection",
      source("C:/ProjectsR/openVacancyTest.R")
    ),
  )
)
shinyApp(ui, server)

Below is the code that is called in tabPanel.

library(shiny)

# Define the UI

ui <- fluidPage(
  titlePanel("Recruitment and selection"),
  sidebarLayout(
    sidebarPanel(
      tags$head(
        tags$link(rel = "stylesheet", href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css")
      ),
      tags$style(
        HTML("
      .green-button {
        background-color: #00FF00;
        color: #FFFFFF;
      }
    ")
      ),
      
      actionButton("register_vacancy", label = HTML('<i class="fas fa-check"></i> Open Vacancy'),style = "background-color: blue; color: #FFFFFF;"),
      br(),
      conditionalPanel(
        condition = "input.register_vacancy > 0",
        textInput("title", "Title:"),
        selectInput("client", "Client:",
                    choices = c(" ", "Jacob Thompson",
                                "Emma Wilson",
                                "Alexander Hughes",
                                "Isabella Brooks",
                                "William Parker",
                                "Sophia Turner",
                                "Benjamin Mitchell" )),
        textInput("contact", "Contact:"),
        textAreaInput("des", "Job description:", value = "Job description"),
        textInput("form", "Form of work:"),
        selectInput("tip", "Hiring type:",
                    choices = c ("CLT",
                                 "CLT-Temporary",
                                 "Internship",
                                 "Legal Person")),
        textInput("cat", "Category:"),
        numericInput("rem", "Remuneration:", value = 0),
        textInput("com", "Comments:"),
        selectInput("experience_level", "Experience Level:",
                    choices = c("Beginner", "Intermediry", "Advanced")),
        br(),
        
        
        textOutput("message"),
        actionButton("copy_data", "Send request")
      )
    ),
    mainPanel(
      conditionalPanel(
        condition = "input.copy_data > 0",
        h3("Vacancy data"),
        tableOutput("copied_data")
      )
    )
  )
)

server <- function(input, output, session) {
  
  copied_data <- reactiveValues(data = data.frame())
  
  
  observeEvent(input$copied_data, {
    title <- input$title
    client <- input$client
    contact <- input$contact
    des <- input$des
    form <- input$form
    tip <- input$tip
    cat <- input$cat
    rem <- input$rem
    com <- input$com
    experience_level <- input$experience_level
      
    new_data <- data.frame(Title = title,
                           Client = client,
                           Contact = contact,
                           Des = des,
                           Form = form,
                           Tip = tip,
                           Cat = cat,
                           Rem = Rem,
                           Com = com,
                           Experience_level = experience_level)
    
    copied_data$data <- rbind(copied_data$data, new_data)
    
    updateTextInput(session, "title", value = "")
    updateSelectInput(session, "client", selected = "")
    updateTextInput(session, "contact", value = "")
    updateTextInput(session, "des", value = "")
    updateTextInput(session, "form", value = "")
    updateSelectInput(session, "tip", selected = "")
    updateTextInput(session, "cat", value = "")
    updateNumericInput(session, "rem", value = NULL)
    updateTextInput(session, "com", value = "")
    updateSelectInput(session, "experience_level", selected = "")
    
    output$copied_data <- renderTable({
      copied_data$data
    })
    
  })
  
  observeEvent(input$copied_data, {
    source("C:/ProjectsR/Email.R",local = TRUE)
  }) 
}

shinyApp(ui, server)

Print of error result. Error True

All attempts below did not correct the error, it stayed the same. First try

tabPanel("My Dashboard",
  invisible({
    source("file.R")
  })
)

Second try

tabPanel("My Dashboard",
  {
    result <- source("file.R", local = TRUE)
  }
)

Third try

tabPanel("My Dashboard",
  {
    eval(parse(file = "file.R"))
  }
)

Fourth try

tabPanel("My Dashboard",
  {
    resultado <- source("file.R", local = TRUE)
  }
)
  • Why are you running `source()` inside the UI? Why not run it inside `server()`? – Captain Hat Jun 19 '23 at 10:45
  • Got it, thanks, but how do I call the source later inside the tabPanel? I tried the following solution and it didn't work. `server <- function(input, output) { result <- reactive({ source("File.R", local = TRUE) myResult }) output$meuTabPanel <- renderUI({ tabPanel("My Panel", verbatimTextOutput("resultOutput") ) }) output$resultOutput <- renderPrint({ result() })` – hud.castro Jun 19 '23 at 11:40
  • What is your end goal here? Maybe you should revise your question - ideally including a [minimal, reprodubile example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that we can help you to solve your problem – Captain Hat Jun 19 '23 at 13:03
  • My ultimate goal is to remove the word TRUE when I render the application's screen, I followed your solution of putting the path in server(), however, I don't know how to call this in tabPanel(). – hud.castro Jun 19 '23 at 15:25
  • Let's take a step back. What is your Shiny app supposed to do? Why do you need to run `source()` in the first place? – Captain Hat Jun 20 '23 at 08:32

0 Answers0