【问题标题】:Open up a shiny app by clicking a link in a different shiny app?通过单击不同闪亮应用程序中的链接打开闪亮应用程序?
【发布时间】:2017-07-10 00:26:34
【问题描述】:

只是想知道这是否可能。我有一个应用程序显示指向某些文件的链接,并且希望在用户单击其中一个链接时打开一个单独的闪亮应用程序。

【问题讨论】:

  • 您是指指向您服务器/帐户上托管的其他应用程序的链接,还是指向外部站点的链接?

标签: r shiny


【解决方案1】:

谢谢卡尔, 我有一个类似的问题,另外需要创建一个根据某些用户操作而变化的动态链接。 我以这种方式解决了(我重新编写了您的 shiny.rstudio.com/gallery 代码)

extract_info <- function(html_line) {
    li <- url_absolute(xml_attr(html_line, 'href'), xml_url(html_line))
    data.frame(li = li, 
               txt = stri_trans_totitle(trimws(gsub("\\-|\\.html", " ", basename(li)))),
               stringsAsFactors = FALSE)
}

mydata.df <- lapply(read_html("http://shiny.rstudio.com/gallery/") %>%
                       xml_find_all('//a'), 
                    function(line) extract_info(line)) %>%
    rbind_pages() %>% 
    dplyr::filter(!duplicated(txt))

ui <- fluidPage(        
    titlePanel("Select shiny apps"),
    sidebarLayout(
        sidebarPanel(
            numericInput(inputId = "myline", label = "Select one line", 
                         value = 1, min = 1, max = NA, step = 1),
            uiOutput("wantedlink")
        ),
        mainPanel(DT::dataTableOutput("mytable"))
    )
)

server <- function(session, input, output) {
    output$mytable <- DT::renderDataTable({ DT::datatable( mydata.df ) })

    mylink <- reactive({ 
        mydata.df$li[input$myline] })
    mytext <- reactive({ 
        mydata.df$txt[input$myline] })

    output$wantedlink <- renderUI({
       HTML(sprintf('<a href = %s target = "_blank">%s</a>', as.character(mylink()), mytext()))
    })
}

shinyApp(ui, server)

【讨论】:

    【解决方案2】:

    要打开外部链接,您可以插入:

    tag("a", list(href = "http://www.myapps.com/otherapp", "Other App"))
    

    HTML(语言)中的“a”标签通常用于表示链接,href 属性是插入路径的位置。下面我整理了一个使用所有 Shiny App 库和帮助链接的快速示例

    ui <- bootstrapPage(
      tag('ul',
    lapply(read_html("http://shiny.rstudio.com/gallery/") %>%
    xml_find_all('//a'), function(i){
    li <- url_absolute(xml_attr(i, 'href'), xml_url(i))
    data.frame(li = li, 
              txt = stri_trans_totitle(
                    trimws(gsub("\\-|\\.html"," ",basename(li)))),
              stringsAsFactors = FALSE)
      }) %>% rbind.pages() %>% 
    dplyr::filter(!duplicated(txt)) %>% apply(., 1, function(x){
        tag("li",list(tag("a", list(href = x[[1]],x[[2]]))))
      }))
    )
    
    server <- function(session, input, output){
    
    }
    
    shinyApp(ui, server)
    

    对于您可以使用的任何指向外部应用程序的链接:

    ext.link <- function(label = NULL, link = NULL){
       tag("a", list(href = link,
           ifelse(!is.null(label), label, basename(link))))
    }
    

    这会在您的应用中生成 html:

    > ext.link(label = "New app", link = "http://mypage.com/new_app")
      <a href="http://mypage.com/new_app">New app</a>
    

    【讨论】:

      猜你喜欢
      • 2013-07-08
      • 1970-01-01
      • 2014-04-11
      • 2016-05-23
      • 1970-01-01
      • 2013-07-04
      • 2016-06-02
      • 2016-02-03
      • 1970-01-01
      相关资源
      最近更新 更多