2

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.

Dan
  • 21
  • 2
  • Unlike a reactive value generated by the `reactive` function, you don't need the parentheses to access a value from a reactive values object generated by `reactiveValues`. `df()$data` should be `df$data`. See if that solves your problem. – divibisan May 17 '18 at 15:22
  • Thanks for the reply! So I've tried that and it got rid of the error - it doesn't display the buttons correctly though, it instead displays the html code for them. – Dan May 17 '18 at 15:32
  • Glad to help with that! You should update your question to reflect your new issue so that people can help you with that. – divibisan May 17 '18 at 15:35

0 Answers0