我有一个反应性df,我想将所有列从factor转换为整数。我在下面添加了可复制的代码。如何对闪亮的应用程序中的所有列进行处理。谢谢。
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow( column(
width = 3, textInput("text1", label = h5("Min"), value = "1")),
DT::dataTableOutput("op"))
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),sidebar,body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda civic","honda accord"),
april = c(.1,.2,.3,.3,.4,.5),
may = c(".3",".4",".5",".2",".1",".5"))
cols_to_change <- reactive({colnames(df)})
dj_class <- reactive({ for(i in cols_to_change()){
class(df[, i]) = "integer"
}
})
output$op <-renderDataTable({
print( sapply(dj_class(),class))
print( sapply(df,class))
df
})
}
shinyApp(ui = ui, server = server)