我在第一个Shiny应用程序上进行选择时收到此错误消息。
以下是以下代码的示例数据框:
# generate sample data
sample_data <- data.frame(
Device = c("Desktop", "Desktop", "Desktop", "Tablet", "Tablet", "Tablet", "Mobile", "Mobile", "Mobile"),
Channel = c("Organic", "Organic", "Organic", "Affiliate", "Affiliate", "Affiliate", "Paid", "Paid", "Paid"),
LandingPageGroup = c("Example.Com", "Example.Com", "Example.Com", "AbTest", "AbTest", "AbTest", "Custom", "Custom", "Custom"),
Date_Range = seq(as.Date("2017-01-01"), as.Date("2017-01-30"), by = 1),
Sessions = ceiling(rnorm(90, mean = 3000, sd = 300)),
Registrations = ceiling(rnorm(90, mean = 800, sd = 100)),
Conversion1 = ceiling(rnorm(90, mean = 400, sd = 50)),
Conversion2 = ceiling(rnorm(90, mean = 20, sd = 7))
)
在ui.R中,我有这个带有输入的侧边栏:
sidebarLayout(
## Sidebar inputs here
sidebarPanel(
selectInput("device",
"Device",
c("Desktop", "Tablet", "Mobile")),
selectInput("channel",
"Channel",
c("Organic", "Affiliate", "Paid")),
selectInput("landing",
"Landing Page Group",
c("Example.Com", "AbTest", "Custom"))
),
## main panel output here
mainPanel(
# Create a new row for the table.
fluidRow(
DT::dataTableOutput("table")
),
br(), br()
)
)
然后,在server.R中,这是我的应用程序的开头,直到我认为相关的代码:
(上面定义的样本数据框,在函数(输入,输出)之前)
library(dplyr)
sample_txdata <- tbl_df(sample_txdata)
function(input, output) {
# create reactive set of data with filters applied by user
filtered <- reactive({
sample_txdata %>%
filter(Device == input$device,
Channel == input$channel,
LandingPageGroup == input$landing
)
})
output$table <- DT::renderDataTable(DT::datatable({
filtered() %>% {code block that does stuff to the data}
该应用程序的工作原理是表格加载并呈现正常。除非我在3个输入过滤器中的一个中进行选择,否则我得到上述错误并且表格消失。有什么想法吗?
答案 0 :(得分:1)
根据您提供的数据,这不是一个闪亮的问题,而是一个&#34;样本数据&#34;问题。选择输入将起作用,但仅适用于以下组合:
unique(sample_txdata[, 1:3])
案例1:Desktop Organic Example.Com
是您选择输入的默认值,这就是您最初在表格中查看数据的原因。