0
votes

I have a Shiny App that takes a text input and shows it on the main panel (I used this answer to build it):

ui.r:

library(shiny)

shinyUI(fluidPage(

    titlePanel("This is a test"),

    sidebarLayout(
      sidebarPanel(
          textInput("text1", "Enter the text", ""),
          actionButton("goButton", "Go")
    ),

      mainPanel(
         h3(textOutput("text1", container = span))
            )
           )
          )
         )

server.r:

shinyServer(function(input, output) {

  cap <- eventReactive(input$goButton, {
    input$text1
  })

  output$text1 <- renderText({
    cap()
  })

})

It worked great until I decided to add a Tabset panel, and show the input on one of the tabs. I modified mainPanel() in ui.r as:

mainPanel(
  tabsetPanel(type = "tabs",
              tabPanel("t1"), 
              tabPanel("t2", 
              tabPanel("t3"), h3(textOutput("text1", container = span)),
        )
      )

After this change, I am getting an error when launching an app:

ERROR: cannot coerce type 'closure' to vector of type 'character'

Is there something I am missing?

1

1 Answers

1
votes

You have to put the content within the tab within the call to tabPanel. Ex:

mainPanel(
  tabsetPanel(
    type = "tabs",
    tabPanel("t1"), 
    tabPanel("t2"), 
    tabPanel("t3", h3(textOutput("text1", container = span)))
  )
)

Thus, server.R is unchanged from you question, and ui.R becomes:

library(shiny)

shinyUI(
  fluidPage(
    titlePanel("This is a test"),
    sidebarLayout(
      sidebarPanel(
        textInput("text1", "Enter the text", ""),
        actionButton("goButton", "Go")
       ),
      mainPanel(
        tabsetPanel(
          type = "tabs",
          tabPanel("t1"), 
          tabPanel("t2"), 
          tabPanel("t3", h3(textOutput("text1", container = span)))
        )
      )
    )
  )
)