我有一个简单的shiny
应用程序,其中在DT
表的某些列中显示百分比。是否可以使搜索框具有与输出相同的格式?
library(shiny)
library(DT)
library(dplyr)
ui <- basicPage(
h2("The mtcars data"),
DT::dataTableOutput("mytable")
)
server <- function(input, output) {
mydata <- mtcars %>%
mutate(mpg = mpg/max(mtcars$mpg),
cyl = cyl/max(mtcars$cyl))
output$mytable = DT::renderDataTable({
datatable(mydata,filter="top", selection="multiple" ) %>%
formatPercentage(c("mpg", "cyl"), 2)
})
}
shinyApp(ui, server)