I am working within a shiny app and I want to be able to access information on the current tab a user is on in a session.
I have a observe event that listens for a parti
Is that what you expected?
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(kableExtra)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1"),
menuItem("2", tabName = "2"),
menuItem("3", tabName = "3"),
menuItem("4", tabName = "4")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
column(
width = 3,
# pickerInput(
# inputId = "metric",
# label = h4("Metric Name"),
# choices = c(
# "alpha",
# "beta"
# ),
#
# width = "100%"
# )
uiOutput("metric")
, actionButton("show", "Help")
)
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
# observeEvent(input$metric, {
# if (input$tab == "1"){
# choices <- c(
# "alpha",
# "beta"
# )
# }
# else if (input$tab == "2") {
# choices <- c(
# "apple",
# "orange"
# )
# }
# else {
# choices <- c(
# "foo",
# "zoo",
# "boo"
# )
# }
# updatePickerInput(session,
# inputId = "metric",
# choices = choices)
# })
output$metric<-renderUI({
if (input$tab == "1"){
choices <- c(
"alpha",
"beta"
)
}
else if (input$tab == "2") {
choices <- c(
"apple",
"orange"
)
}
else {
choices <- c(
"foo",
"zoo",
"boo"
)
}
pickerInput(
inputId = "metric",
label = h4("Metric Name"),
choices = choices,
width = "100%"
)
})
faq1 <- data.frame(
Findings = c(
"lorem ipsum"
))
faq2 <- data.frame(
Findings = c(
"lorem ipsum bacon"
))
faq3 <- data.frame(
Findings = c(
"lorem ipsum bacon bacon"
))
observeEvent(input$show, {
showModal(modalDialog(
title = "Guildlines",
tableOutput("kable_table"),
easyClose = TRUE
))
})
faqtext<-reactive({
if (input$tab == "1"){
return(faq1)
}
else if (input$tab == "2") {
return(faq2)
}
else if (input$tab == "3") {
return(faq3)
}
else {
return(benchmark_faq)
}
})
output$kable_table<-function(){
kable(faqtext()) %>%
kable_styling("striped", full_width = F) %>%
column_spec(1, bold = T, border_right = T)%>%HTML
}
}
shinyApp(ui = ui, server = server)