嵌入反应生成的URL有光泽

Yu *_*ang 7 url r shiny

我想在我的闪亮应用程序中显示一个链接,该链接指向根据用户输入生成的URL.我不想显示URL的全文.我知道如果事先知道URL,可以使用a(href ="",label ="")函数,但在这种情况下,URL取决于用户的输入.以下不起作用:

ui <- fluidPage(
    titlePanel("Show map of a given state"),
    sidebarLayout(
        sidebarPanel(
            textInput("state", label = "State", value = "CA", placeholder = "California or CA"),
            actionButton("showU","Show map")
        ),
        mainPanel(
            conditionalPanel(
                condition = "input.showU > 0",
                htmlOutput("url"),
                a(href=htmlOutput("url"),"Show in Google Map",target="_blank")
            )
        )
    )
)

server <- function(input, output){
    observeEvent(input$showU,{
    output$url <-renderUI({paste("https://www.google.com/maps/place/", input$state, sep="")})
    })
}

shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)

我希望我可以点击"在谷歌地图上显示",然后转到即时生成的网址.请帮帮我,谢谢.

Hub*_*rtL 5

您需要renderUI一起使用uiOutput以反应更新UI:

library(shiny)
ui <- fluidPage(
  titlePanel("Show map of a given state"),
  sidebarLayout(
    sidebarPanel(
      textInput("state", label = "State", value = "CA", placeholder = "California or CA"),
      actionButton("showU","Show map")
    ),
    mainPanel(
      conditionalPanel(
        condition = "input.showU > 0",
        uiOutput("url")
      )
    )
  )
)

server <- function(input, output){
  observeEvent(input$showU,{
    output$url <-renderUI(a(href=paste0('https://www.google.com/maps/place/', input$state),"Show in Google Map",target="_blank"))
  })
}

shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)