What is the function of an underscore in R? For example, in the code below, the line: input$tbl_rows_current
; determines that the current data being displayed is placed into the variable filtered_data
; however, if I change it to input$tbl_rows_all
, all the data filtered is placed into the variable filtered data
.
I understand how it functions here, but what is its general use?
ui = fluidPage(dataTableOutput('tbl'),
plotOutput('plot1')
)
server = function(input, output) {
output$tbl = renderDataTable({
datatable(KSI, filter="top",rownames=TRUE,options = list(lengthChange = FALSE))
})
output$plot1 = renderPlot({
filtered_data <- as.numeric(*input$tbl_rows_current*)
print(filtered_data)
})
}
shinyApp(ui=ui, server=server)
Underscores are not semantically meaningful, they're just part of the variable name. (In the prehistoric era, _
was synonymous with the assignment operator <-
and couldn't be used in variable names.) tbl_rows_current
and tbl_rows_all
are just two particular elements of the input
list. Depending on the preferences of the author, they could equally well have been called
tblrowscurrent
and tblrowsall
TblRowsCurrent
and TblRowsAll
tbl.rows.current
and tbl.rows.all
oranges
and jackhammers
If you like this sort of thing, check out Are there any official naming conventions for R?
Note, however, that you can't change these names; only the original package author could have. These elements are defined not in your code, but on the shiny side -- it's part of the shiny API/interface that it's expecting to see these particular elements (i.e., elements with these particular names).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With