Page refresh Button in R shiny

僤鯓⒐⒋嵵緔 提交于 2019-11-27 06:22:15

问题


I tried to implement a page refresh button following the link here. However when I tried deploying to shinyapp.io, it failed and asked for installing package V8 which I had already done. The app was working fine on the machine. The code I used is:

jsResetCode <- "shinyjs.reset = function() {history.go(0)}",

useShinyjs(), # Include shinyjs in the UI

extendShinyjs(text = jsResetCode), # Add the js code to the page   

p(actionButton("reset_button", "Reset Tool"))

In server.R:

observeEvent(input$reset_button, {js$reset()}) 

Is there any way to do this without shinyjs?


回答1:


Just to be complete, the code below is a minimal example of a working Shiny app that uses a "refresh" button

library(shiny)
library(shinyjs)

jscode <- "shinyjs.refresh = function() { history.go(0); }"

ui <- fluidPage(
  useShinyjs(),
  extendShinyjs(text = jscode),
  textInput("text", "Text"),
  actionButton("refresh", "Refresh app")
)

server <- function(input, output, session) {
  observeEvent(input$refresh, {
    js$refresh();
  })
}

shinyApp(ui = ui, server = server)

Edit: Since shiny version 0.13.0, it's possible to refresh the page using Shiny's session$reload() function



来源:https://stackoverflow.com/questions/34142841/page-refresh-button-in-r-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!