My question is an extension of this question: R Shiny: Handle Action Buttons in Data Table
I am trying to add reactive buttons to a data table that is generated reactively.
Basically, my table is subsetted from a dataframe based on a search term entered by the user. I'd like to have buttons in the subsetted and displayed table, but instead of the buttons appearing as in the linked question, I get HTML code for them.
Here's the server code:
server = function(input, output, session) {
table<-reactive({
filter(evidence_test,grepl(input$search,evidence_abstract,ignore.case=TRUE))[,c(input$show_vars)]
})
shinyInput <- function(FUN, len, id, ...) {
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), ...))
}
inputs
}
df<-reactive({reactiveValues(
data=data.frame(
table(),
Actions = shinyInput(actionButton, nrow(table()), 'button_', label = "Fire", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ),
stringsAsFactors = FALSE
)
)
})
observeEvent(input$select_button, {
selectedRow <- as.numeric(strsplit(input$select_button, "_")[[1]][2])
})
output$tbl <- DT::renderDataTable({
df()$data
});
output$myText <- renderText({
colnames(df$data)
})
}
And here's the UI code:
ui = fluidPage(
headerPanel("Search for article terms"),
sidebarPanel(
textInput(inputId="search",value="kras",label="Search for a term", width=400),
checkboxGroupInput(inputId='show_vars', label='Columns to show:', dbListFields(database,"evidence_test"),
selected = c("evidence_title","evidence_abstract","evidence_score","evidence_priority"))
),
mainPanel(
DT::dataTableOutput("tbl")
)
)
Thanks for the help.