Shinyjs: refresh the page using tabpanel

Created on 31 May 2016  路  3Comments  路  Source: daattali/shinyjs

Hi Dean,

Is it possible to refresh(reload application) webpage based on click event on the tabset panel ? I have a home tab on my navbar page, whenever i click that tab the whole system need to get refreshed. Currently i am using an action button to do it . i tried to use shinyjs in tabpanel but its not working. Not sure how to handle it.

Most helpful comment

You can do something like this

library(shiny)
library(shinyjs)

jscode <- "shinyjs.refresh = function() { location.reload(); }"

shinyApp(
  ui = tagList(
    useShinyjs(),
    extendShinyjs(text = jscode, functions = "refresh"),
    navbarPage(
      "test",
      id = "navbar",
      tabPanel(title = "tab1", "tab 1"),
      tabPanel(title = "tab2", "tab 2"),
      tabPanel(title = "Refresh", value = "refresh")
    )
  ),
  server = function(input, output, session) {
    observe({
      if (input$navbar == "refresh") {
        js$refresh();
      }
    })
  }
)

All 3 comments

You can do something like this

library(shiny)
library(shinyjs)

jscode <- "shinyjs.refresh = function() { location.reload(); }"

shinyApp(
  ui = tagList(
    useShinyjs(),
    extendShinyjs(text = jscode, functions = "refresh"),
    navbarPage(
      "test",
      id = "navbar",
      tabPanel(title = "tab1", "tab 1"),
      tabPanel(title = "tab2", "tab 2"),
      tabPanel(title = "Refresh", value = "refresh")
    )
  ),
  server = function(input, output, session) {
    observe({
      if (input$navbar == "refresh") {
        js$refresh();
      }
    })
  }
)

Thanks I understood it but my page is like a google search page with a home tab whenever i open it keeps on refreshing. The idea was good thanks.

You can do something like this

library(shiny)
library(shinyjs)

jscode <- "shinyjs.refresh = function() { location.reload(); }"

shinyApp(
  ui = tagList(
    useShinyjs(),
    extendShinyjs(text = jscode, functions = "refresh"),
    navbarPage(
      "test",
      id = "navbar",
      tabPanel(title = "tab1", "tab 1"),
      tabPanel(title = "tab2", "tab 2"),
      tabPanel(title = "Refresh", value = "refresh")
    )
  ),
  server = function(input, output, session) {
    observe({
      if (input$navbar == "refresh") {
        js$refresh();
      }
    })
  }
)

Hello, If I only want to refresh a certain tab, not the "location", how can I access the TabName, please?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gadepallivs picture gadepallivs  路  6Comments

sammerk picture sammerk  路  3Comments

shosaco picture shosaco  路  4Comments

pssguy picture pssguy  路  15Comments

stratosfmos picture stratosfmos  路  71Comments