Reputation: 91
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)
Upvotes: 0
Views: 285