我希望能够从一个动作链接的末尾生成一个动作链接。因此,当一个人到达可折叠树的尽头时。
我可以看到如何传递数据表中的链接,但可以将该数据表传递给可折叠树。
创建一个具有可观察事件的动作链接的数据框。然后,将其传递到可折叠的树中,该树可将人们路由到我闪亮的应用程序中的正确列。
df <- data.frame('Start' = c('Beginning', 'Beginning', 'Beginning',
'Beginning','Beginning','Beginning'),
'Point_1' = c('California',
'California','California','Texas','Texas','Florida'),
'Point_2' = c('Colorado', 'Georgia', 'Michigan', 'Ohio',
'Arizona',''),
'Destination'= c('Nevada', 'Alabama', 'Virginia',
'Louisiana', 'Oklahoma', 'Washington'))
collapsibleTree(
df,
#DT::dataTableOutput("collapsible_tree"),
hierarchy = c("Point_1", "Point_2", "Destination"),
root = "Start",
width = 1200,
height = "900px",
zoomable = TRUE,
collapsed = TRUE,
fillByLevel = TRUE,
attribute = "leafCount",
nodeSize = "leafCount",
tooltipHtml = "tooltip"
)
然后想进行观察事件
shinyApp(
ui <- fluidPage(
titlePanel("Destination Dashboard"),
theme = shinytheme("united"),
navlistPanel(id='nav', widths = c(2, 10),
tabPanel('Tree',
collapsibleTree(
DT::dataTableOutput("collapsible_tree"),
hierarchy = c("Point_1", "Point_2", "Destination"),
root = "Start",
width = 1200,
height = "900px",
zoomable = TRUE,
collapsed = TRUE,
fillByLevel = TRUE,
attribute = "leafCount",
nodeSize = "leafCount",
tooltipHtml = "tooltip"
)),
tabPanel('Summary2', dataTableOutput('summary')),
tabPanel("Nevada", dataTableOutput('Nevada')),
tabPanel("Alabama", dataTableOutput('Alabama')),
tabPanel("Virginia", dataTableOutput('Virginia')),
tabPanel("Louisiana", dataTableOutput('Louisiana')),
tabPanel("Oklahoma", dataTableOutput('Oklahoma')),
tabPanel("Washington", dataTableOutput('Washington'))
)
),
server <- function(input, output, session) {
output$collapsible_tree<- renderDataTable({
data <- df %>%
mutate(Destination = shinyInput(actionLink, nrow(df), 'button_', label = Destination, onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ))
table <- datatable(data, escape = FALSE , selection = 'none')
table
})
observeEvent(input$select_button, {
selectedRow <- as.numeric(strsplit(input$select_button, "_")[[1]][2])
updateNavlistPanel(session, 'nav', as.character(df[selectedRow, 1]))
})
}
)
未显示数据表内容,以缩短发布代码的长度。
我希望将其路由到包含内容的适当选项卡。与此示例几乎相同:
Clickable links in Shiny Datatable
但是将其传递到可折叠树中,我认为rendercollapsibleTree没有闪亮的选择。当我尝试通过这样的操作时,我得到:
UseMethod(“ collapsibleTree”)中的错误: 没有适用于'collapsibleTree'的适用方法应用于类“ c('shiny.tag.list','list')”的对象
谢谢!