Tony J Duan
Tony J Duan

Reputation: 23

Bookmark does not work at Shiny Dashboard?

I am able to use Bookmark at Shiny ,But does not work at Shiny Dashboard .

bookmarkButton() give me a new url. But i enter it ,it dose not get me the new result.

library(shinydashboard)

ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(

    box(plotOutput("plot1", height = 250)),

    box(
    title = "Controls",
    sliderInput("slider", "Number of observations:", 1, 100, 50),
    bookmarkButton()
  )
  )
  )
  )

server <- function(input, output,session) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
enableBookmarking(store = "url")
shinyApp(ui, server)

Upvotes: 1

Views: 805

Answers (1)

Florian
Florian

Reputation: 25385

Your UI should be a function, as is indicated by the error you get, see also the documentation

Working example:

library(shinydashboard)

ui <- function(request) { 
  dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(

      box(plotOutput("plot1", height = 250)),

      box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50),
        bookmarkButton()
      )
    )
  )
)
}

server <- function(input, output,session) {
  set.seed(122)
  histdata <- rnorm(500)
  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })

}
enableBookmarking(store = "url")
shinyApp(ui, server)

Hope this helps!

Upvotes: 3

Related Questions