书签在 Shiny Dashboard 不起作用?

Bookmark does not work at Shiny Dashboard?

我可以在 Shiny 中使用 Bookmark,但在 Shiny Dashboard 中不起作用。

bookmarkButton() 给我一个新的 url。但是我输入了它,它并没有给我新的结果。

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)

您的 UI 应该是一个函数,如您收到的错误所示,另请参阅 the documentation

工作示例:

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)

希望对您有所帮助!