Mickey_NC Mickey_NC - 1 month ago 15
R Question

R shiny : renderDataTable of a global environment object

I have an object named "map_choice" which value can be : "1_1","1_2","1_3"...
And I have created some data frames objects in my global environment named : "T_1_1","T_1_2","T_1_3"...
I'm trying to render the matching data frame with these lines in my Server.R but I have this error message : "'data' must be 2-dimensional (e.g. data frame or matrix)"

Server.R :

output$tab_map = renderDataTable({paste(T_,map_choice)}) # paste to
match data frame name

output$box1 <- renderUI({
box(title = input$maps, dataTableOutput("tab_map")) # dynamic title of
the box
})


And this line in Ui.R :

uiOutput("box1")


I suppose it's an easy thing to do but I didn't manage to do it.

Thank you for helping a beginner.

Answer

What you need is get. Also make sure you use paste0

output$tab_map = renderDataTable({
  get(paste0("T_",map_choice))
})
Comments