我试图通过单击数据表中嵌套的链接导航到下一个选项卡。
第一次使用时效果很好Shiny.bindAll。在这里您可以找到 Joe Cheng 关于该功能使用的解释。
但是,当通过过滤输入数据来重新渲染数据表时,selectInput从 2 切换回 1 时绑定会丢失:
library(shiny)
library(DT)
library(dplyr)
ui <- fluidPage(tabsetPanel(
id = "panels",
tabPanel("A",
selectInput("sel", "Select", choices = c(1,2)),
DTOutput("tab")),
tabPanel("B",
h3("Some information"),
tags$li("Item 1"),
tags$li("Item 2"),
actionLink("goToTabPanelA", "goToTabPanelA")
)
))
server <- function(input, output, session) {
DF <- data.frame(a = c(1,2),
b = c(HTML('<a id="goToTabPanelB1" class="action-button" href="#">goToTabPanelB1</a>'),
HTML('<a id="goToTabPanelB2" class="action-button" href="#">goToTabPanelB2</a>')))
output$tab <- renderDataTable({
datatable(
DF %>% filter(a %in% input$sel),
escape = FALSE,
selection = 'none',
options …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个表(使用 DT,请不要使用 rhandsontable),该表几乎没有现有列,一个 selectinput 列(其中每行都有可供选择的选项),最后是另一列,该列将根据用户选择进行填充从每行的 selectinput 下拉列表中。
在我的示例中,“反馈”列是用户下拉选择列。我无法更新“分数”列,该列将基于“反馈”列下拉列表中的选择。
if(interactive()){
library(DT)
library(shiny)
tbl1 <- data.frame(A = c(1:10), B = LETTERS[1:10], C = c(11:20), D = LETTERS[1:10])
ui <- fluidPage(
DT::dataTableOutput(outputId = 'my_table')
)
server <- function(input, output, session) {
rv <- reactiveValues(tbl = tbl1)
observe({
for (i in 1:nrow(rv$tbl)) {
rv$tbl$Feedback[i] <- as.character(selectInput(paste0("sel", i), "",
choices = c(1,2,3,4)
))
if(!is.null(input[[paste0("sel", i)]])) {
if(input[[paste0("sel", i)]] == 1) {
rv$tbl$Score[i] <- 10
} else if(input[[paste0("sel", i)]] == 2) {
rv$tbl$Score[i] <- 20
} …Run Code Online (Sandbox Code Playgroud)