在 Shiny 应用程序中重定向

编程入门 行业动态 更新时间:2024-10-25 09:33:52
本文介绍了在 Shiny 应用程序中重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试让我的 Shiny 应用程序将用户重定向到另一个页面.我正在使用 httr 发送 GET 请求并查看用户是否登录.如果他没有登录,我想将他重定向到另一个链接.

I'm trying to make my Shiny app to redirect the user to another page. I'm using httr to send GET requests and see if the user is logged in. If he's not, I want to redirect him to another link.

我可以只使用 R/Shiny 来做到这一点,还是需要一些额外的库?

Can I do that using R / Shiny only, or do I need some extra libraries?

示例:

library(httr) library(shiny) shinyServer(function(input, output) { rv <- reactiveValues() rv$mytoken = session$request$token observeEvent(input$button1, { rv$a <- GET("my.url:3405/authtoken", add_headers( .headers = c("token" = rv$mytoken) )) if (rv$a$status_code == 200) { } else { # redirect magic } }) } shinyUI(fluidPage( actionButton(button1, "btn") ))

推荐答案

这里如果不是 true

library(shiny) jscode <- "Shiny.addCustomMessageHandler('mymessage', function(message) {window.location = 'www.google';});" ui <- fluidPage( tags$head(tags$script(jscode)), checkboxInput("Redirect","Redirect",value = T) ) server <- function(input, output, session) { observeEvent(input$Redirect,{ if(!input$Redirect){ session$sendCustomMessage("mymessage", "mymessage") } }) } shinyApp(ui,server)

更多推荐

在 Shiny 应用程序中重定向

本文发布于:2023-10-23 13:43:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   重定向   Shiny

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!