0

I am currently trying to create an R Shiny app with multiple tab panels. On one tab panel I would like to enter some numbers and then depending on a button show and hide the numbers entered. I use shinyjs for the hiding and verbatimTextOutput to get the numbers but when I run the app nothing happens after klicking the button.

Does anyone know how to fix this?

Here is a minimum example of my code:

library(shiny)
library(shinyjs)

ui <- tagList(
  useShinyjs(),
  navbarPage(
    "shinyjs with navbarPage",
    tabPanel("tab1",
             actionButton("button1", "Click me"),
             div(id = "hello", "Hello!")),
    tabPanel("tab2",
             sidebarPanel(
               textInput('str_values', 'Enter values in comma delimited format (e.g. 5.6, 6.7, 4.1, ...)', "")),
             mainPanel(
               actionButton("button2", "Click me"),
               div(id = "div_values",verbatimTextOutput("oid_values")))
    )))

server <- function(input, output, session) {
  num_values <- reactive(as.numeric(unlist(strsplit(input$str_values,","))))
  
  observeEvent(input$button1, {
    toggle("hello")
  })
  
  observeEvent(input$button2, {
    toggle("div_values")
    output$oid_values <- renderPrint({
      cat("your output:\n")
      print(num_values())
    })
  })
}

shinyApp(ui, server)
Nerd
  • 61
  • 5
  • 2
    The `id` of the `verbatimTextOutput` in the UI is `oid_values` but you refer to it with `output$oid_SIBDQ` in the server. – Limey Jun 30 '22 at 15:32
  • 1
    Thank you, that was the problem. Now I feel stupid :D – Nerd Jun 30 '22 at 16:30

0 Answers0