[英]Error in Hyperlink Shiny datatable
我有這段代碼可以使用paste0函數創建超鏈接。 但是當單擊時,URL讀取:
http://127.0.0.1:4350/www.companyname.com/test/test/product.html
http://127.0.0.1:4350/始終在之前。 在另一節的其余代碼中,它工作正常。
在URL1列中,數據為www.companyname.com/test/test/product.html,此處為一些代碼:
ui
(...)
tabsetPanel(
tabPanel("Products", dataTableOutput("table1")),
(...)
服務器
(...)
shinyServer(function(input, output, session) {
output$table1 <- DT::renderDataTable({
search <- input$name
df <- subset(products, grepl(search, products$Name, ignore.case = TRUE)==TRUE)
df$Model <- paste("<a href= '",df$URL1,"' target='_blank '>",df$Model,"</a>")
df2 <- subset(df, Clonality == input$clonality)
df3 <- df2[,tbl]
colnames(df3) <- c("Name", "Model", "Short Description", "Human Gene Symbol", "Sizes", "Price Pounds", "Price Dollars", "Price Euros", "Reviews" )
datatable(df3, escape = FALSE)%>%formatStyle("Reviews",backgroundColor=styleInterval(1.10, c("red", "green")))%>%formatStyle("Name","Price Dollars",backgroundColor=styleEqual("132 214.5 264", "orange"))
})
(...)
URL1列中的數據是www.companyname.com/test/test/product.html
如果您在網址前添加http://,則應該可以。 該列中的網址應為:
http://www.companyname.com/test/test/product.html
希望能奏效。
根據您的評論,您的數據如下所示:
Model URL1
1 www.companyname.com/test/test/product.html
2 www.companyname.com/test/test/product.html
這是使代碼正常工作的最小示例:
library(shiny)
df <- data.frame(Model = c("1", "2"), URL1 = c("www.companyname.com/test/test/product.html", "www.companyname.com/test/test/product.html"))
ui <- fluidPage(DT::dataTableOutput("table"))
server <- function(input, output){
output$table <- DT::renderDataTable({
df$Model <- paste0("<a href= '","http://",df$URL1,"' target='_blank '>",df$Model,"</a>")
DT::datatable(df, escape = FALSE)
})
}
shinyApp(ui, server)
您的URL1缺少http://
,這導致了錯誤。 另外,我必須使用paste0
來代替paste
,以便沒有不必要的空格。
希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.