如何在“闪亮书签”中排除参数?

时间:2019-01-15 14:49:14

标签: r shiny

我正在创建一个仪表板,我想从书签中排除一些参数。

这是MWE:

library(shiny)

# Define UI for application that draws a histogram
ui <- function(request) {
    fluidPage(

        # Application title
        titlePanel("Old Faithful Geyser Data"),

        # Sidebar with a slider input for number of bins 
        sidebarLayout(
            sidebarPanel(
                sliderInput("bins",
                            "Number of bins:",
                            min = 1,
                            max = 50,
                            value = 30),
                selectInput(
                    "y",
                    "Year:",
                    choices = 1990:2000,
                    selected = 1990,
                    selectize = TRUE
                )
            ),

            # Show a plot of the generated distribution
            mainPanel(
                plotOutput("distPlot")
            )
        )
    )
}

# Define server logic required to draw a histogram
server <- function(input, output, session) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })

    observe({
        # Trigger this observer every time an input changes
        # strip shiny related URL parameters
        grep("selectized", reactiveValuesToList(input), value = TRUE, invert = TRUE)
        session$doBookmark()
    })

    onBookmarked(function(url) {
        updateQueryString(url)
    })
}

# Run the application 
enableBookmarking("url")
shinyApp(ui = ui, server = server)

它有效并返回此有效(且可编辑)URL http://127.0.0.1:7449/?_inputs_&bins=30&y="1996"&y-selectized=""

我想忽略“ selectized”参数,并将其从书签中排除,或者至少从URL中删除它,只要它完全不影响任何内容。我不知道为什么grep在这里不起作用。

1 个答案:

答案 0 :(得分:1)

您可以在服务器功能中使用setBookmarkExclude()(然后不再需要grep()):

setBookmarkExclude("y-selectized")