R闪亮路由器重定向到包含参数的URL

问题描述 投票:0回答:1

我想使用参数[[https://www.google.com.tw/webhp?newwindow=1重定向到URL,在基本的闪亮应用中效果很好,如下所示:

library(shiny) jscode <- "Shiny.addCustomMessageHandler('mymessage', function(message) {window.location = 'https://www.google.com.tw/webhp?newwindow=1';});" 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.router

的范围内时不起作用,请参见下面的代码以获取更多详细信息。我的最终目标是仅重定向到包含参数的side页面。预先感谢。library(shiny) library(shiny.router) jscode <- "Shiny.addCustomMessageHandler('mymessage', function(message) {window.location = 'https://www.google.com.tw/webhp?newwindow=1';});" # This generates menu in user interface with links. menu <- ( tags$ul( tags$li(a(class = "item", href = route_link("home"), "Home page")), tags$li(a(class = "item", href = route_link("side"), "Side page")) ) ) # This creates UI for each page. page <- function(title, content) { div( menu, titlePanel(title), p(content), actionButton("switch_page", "Click to switch page!") ) } # Both sample pages. home_page <- page("Home page", uiOutput("current_page")) side_page <- page("Side page", uiOutput("current_page")) # Creates router. We provide routing path, a UI as # well as a server-side callback for each page. router <- make_router( route("home", home_page, NA), route("side", side_page, NA) ) # Create output for our router in main UI of Shiny app. ui <- shinyUI(fluidPage( router_ui() )) server <- shinyServer(function(input, output, session) { router(input, output, session) output$current_page <- renderText({ page <- get_page(session) sprintf("Welcome on %s page!", page) }) observeEvent(input$switch_page, { if (is_page("home")) { #change_page("side") session$sendCustomMessage("mymessage", "mymessage") } else if (is_page("side")) { change_page("home") } }) }) shinyApp(ui, server)
r shiny router
1个回答
0
投票
答案如下:
© www.soinside.com 2019 - 2024. All rights reserved.