How to get shiny state_id from the url?

The following code will create a url, such as http://172.26.181.98:11111/?_state_id_=c5c5396f9e4cbad1. If I want to get the state_id and show it in the output$stateid, how should I do?

ui <- function(request) {
  fluidPage(
    plotOutput("plot"),
    sliderInput("n", "Number of observations", 1, nrow(faithful), 100),
    verbatimTextOutput('stateid')
  )
}

server <- function(input, output, session) {
  output$plot <- renderPlot({
    hist(faithful$eruptions[seq_len(input$n)], breaks = 40)
  })
  
  observeEvent(
    reactiveValuesToList(input), 
    session$doBookmark()
  )
  
  onBookmarked(updateQueryString)
}

app <- shinyApp(ui, server, enableBookmarking = "server")
runApp(app, host = "0.0.0.0", port = 11111)

output$stateid <- renderprint(get_state_id)
I don' t know how to write the get_state_id.

Never mind, I already solve my problem.

library(shiny)

ui <- function(request) {
  fluidPage(
    plotOutput("plot"),
    sliderInput("n", "Number of observations", 1, nrow(faithful), 100),
    verbatimTextOutput('stateid')  # Output for displaying state_id
  )
}

server <- function(input, output, session) {
  output$plot <- renderPlot({
    hist(faithful$eruptions[seq_len(input$n)], breaks = 40)
  })

  # Observe any input changes and trigger bookmarking
  observeEvent(
    reactiveValuesToList(input),
    {
      session$doBookmark()
    }
  )

  onBookmarked(
    fun = function(url){
      updateQueryString(url)
      output$stateid <- renderPrint(url)
    }
  )
}

app <- shinyApp(ui, server, enableBookmarking = "server")
runApp(app, host = "0.0.0.0", port = 11111)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.