zesla
zesla

Reputation: 11793

How to make an infomation button in shiny dashboard

I would like to show a information button in my shiny app, where user can click and an text (information) box pop out with some text there. This is for users to click on the button to get some general description about some part of my shiny app.

For some reason, I could not find it in shiny or shinydashboard for that purpose. Does anyone know how I can make the button? Thanks.

Upvotes: 4

Views: 5137

Answers (2)

Pork Chop
Pork Chop

Reputation: 29387

There is a neat package was built called rintrojs which gives you the ability to describe the operations of the shiny app, you can wrap any object into it. More example can be found here https://github.com/carlganz/rintrojs

library(shiny)
library(rintrojs)

ui <- fluidPage(
    introjsUI(),
    column(2,
           br(),
           actionButton("help", "About this Page")
    ),
    column(2,
           introBox(
               selectInput("Task", label = "Select Task",choices =  c("Please select","Upload","Analyze Data")),
               data.step = 1,data.intro = "This is the selectInput called Task, you do xyz with this"
           )
    ),
    column(2,
           introBox(
               selectInput(
                   "breaks", "Breaks",
                   c("Sturges",
                     "Scott",
                     "Freedman-Diaconis",
                     "[Custom]" = "custom")),
               data.step = 2,data.intro = "This is the selectInput called breaks, you do xyz with this"
           )
    ),
    column(2,
           introBox(
               sliderInput("breakCount", "Break Count", min=1, max=1000, value=10),
               data.step = 3,data.intro = "This is the sliderInput called breakCount, you do xyz with this"
           )
    )
)


# Define server logic required to draw a histogram
server <- function(input, output,session) {
    observeEvent(input$help,
                 introjs(session, options = list("showBullets"="false", "showProgress"="true", 
                                                 "showStepNumbers"="false","nextLabel"="Next","prevLabel"="Prev","skipLabel"="Skip"))
    )

}

# Run the application 
shinyApp(ui = ui, server = server)

enter image description here

Upvotes: 6

bs93
bs93

Reputation: 1316

Here are 2 possibilities using 'dropMenu()' from the shinyWidgets package and a modal dialogue as suggested in the comments. In this example a button is placed in the dashboard header that opens an information panel or an action button in the dashboard body can be clicked to bring up a separate window.

Placing a button in the dashboard header will allow it to persist regardless of the tab that is activated. This might be helpful if the menu needs to always be accessed.

library(shiny)
library(shinydashboard)
library(shinyWidgets)

ui <- dashboardPage(
  dashboardHeader( title = "app",
                   tags$li(class = "dropdown",
                           dropMenu(
                             dropdownButton("Info", status = 'success', icon = icon('info')),
                             h3(strong('Information')),
                             br(),
                             h5('This is really helpful'),
                             textInput('text', 'You can also put UI elements here'),
                             placement = "bottom",
                             arrow = TRUE)

                   )

  )
  ,
  dashboardSidebar(),
  dashboardBody(actionButton('help', 'Help'))
)

server <- function(input, output) { 

  observeEvent(input$help,{
    showModal(modalDialog(
      title = "Help!",
      "Information",
      textInput('text2', 'You can also put UI elements here')
    ))
  })
  }

shinyApp(ui, server)

enter image description here enter image description here

Upvotes: 4

Related Questions