In my shiny app, I'm trying to create a hyperlink that opens an html file, created from an R Markdown file, to a certain section based on the current tab of the app the user is on.
Here's an excerpt from the ui and server code I'm using.
ui <- fluidPage(title = "App Title",
dashboardPage(title = "App Title",
dashboardHeader(tags$li(a(href = paste0('Help_File.html', textOutput(page), target="_blank", icon("question"), title = "Help"), class = "dropdown")),
dashboardSidebar(sidebarMenu(id = "tabs",
menuItem(text = 'Tab 1', tabName = 'tab1'),
menuItem(text = 'Tab 2', tabName = 'tab2'),
menuItem(text = 'Tab 3', tabName = 'tab3')
)
)
server <- function(input, output, session) {
output$page <- renderText({
if(input$tabs == 'tab1') {'#page_1'}
else if (input$tabs == 'tab2') {'#page_2'}
else if (input$tabs == 'tab3') {'#page_3'}
else ''
})
}
When I run the app, I get the error "ERROR: cannot coerce type 'closure' to vector of type 'character'". If I put single quotes around page
in the textOutput
function in the ui, the app runs but the file doesn't open. I think either the textOuput
function is wrong or the renderText
function in the server is wrong but I'm not sure what the correct syntax is.