also please why is there a , (comma) at the end of index above statement 2]**,**]? and if not put in it gives error Error in [.data.frame: undefined columns selected.
Your first question: - the tilde notation - is kinda tricky. I tells leaflet to interpret the formula within context of the leaflet data. The examples should start with something like leaflet(data = something) where the something is a data frame - likely quakes.
So what the fit bounds does is it checks the data object of the leaflet call, and calculates the min & max over long and lat colums. Similar thing is with variables "without file name" - the values = ~mag means it will pull values from column mag from the data object.
I mentioned it was tricky because this is a construction you don't see very often.
As for the second: this is on the other hand rather common use case. You are subsetting the quakes data frame by a somewhat complicated logical vector - quakes$mag >= input$range[1] & quakes$mag <= input$range[2] that will filter out rows meeting criteria specified. Since you do not wish to filter columns in any way you just leave the part after comma blank, but the coma has to be there since the quakes object is two dimensional - it has both rows and columns.
To put it into more context: mtcars[1, ] gives you first row of mtcars (Mazda RX4). mtcars[,1] will give you the first column of mtcars (miles per gallon). mtcars[2,2] will give you the value of second column & second row of mtcars = 6 cylinders of Mazda RX4 Wag.