我在下面有一个简单的闪亮应用程序,我希望能够根据复选框组中“INT”或“DOM”的选择来选择数据范围。但我不能让它发挥作用。我尝试使用min
和max
时出错。
我用以下内容重新创建了数据框:
OriginId = c("INT", "DOM", "INT","DOM")
RequestedDtTm = c("2017-01-16 16:43:33
", "2017-01-17 16:43:33
", "2017-01-18 16:43:33
","2017-01-19 16:43:33")
testdata = data.frame(OriginId,RequestedDtTm)
## ui.R ##
library(shinydashboard)
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Change View", tabName = "widgets", icon = icon("th"))
)
),
## Body content
dashboardBody(
tabItems(
# First tab content
# Second tab content
tabItem(tabName = "widgets",
fluidRow(
box(title="Histogram 1",width = 12,
column(4,
checkboxGroupInput("checkGroup2", label = h3("Checkbox group"),
choices = list("Show Domestic" = "DOM", "Show International" = "INT"),
selected = "DOM")
),
column(4,
uiOutput("dt1")
),
column(4,
numericInput("num", label = h3("Numeric input"), value = 1)
)
))
)
)
)
)
#server.r
server <- function(input, output) {
output$dt1<-renderUI({
dateRangeInput('dateRange',
label = 'Date range',
start = min(subset(testdata[,2],testdata$OriginId %in% input$checkGroup2)), end = max(subset(testdata[,2],testdata$OriginId %in% input$checkGroup2))
)
})
}
答案 0 :(得分:1)
您是否还收到错误消息:‘min’ not meaningful for factors
?
如果是,则表示您尝试使用min()
因子,这是不允许的。
要在示例数据上解决此问题,您可以执行testdata = data.frame(OriginId,RequestedDtTm, stringsAsFactors = FALSE)
。
如果您的真实数据确实存在因素,则可以在调用as.character()
之前将其包裹在min()
中,例如min(as.character(subset(........)))
。
当然max()
同样如此。
答案 1 :(得分:0)
我用as.POSIXct()
解决了这个问题。