在闪亮的应用程序中显示数据 table,列显示在 checkboxGroupInput 上
Displaying data table in shiny app, columns displayed conditional on checkboxGroupInput
我正在尝试在闪亮的应用程序中呈现数据 table。当我在没有任何条件参数的情况下通过它时,它显示得很好。当我尝试使显示的变量以来自 checkBoxGroup 小部件的输入为条件时出现问题。
这是我的代码的相关部分:
server.R
library(shiny)
library(ggplot2)
library(pander)
library(plyr)
load("data/ages.data.rda")
load("data/test.data.rda")
load("data/refine.data.rda")
shinyServer(function(input, output) {
output$tafla.gogn <- renderDataTable({
dataset <- switch(input$data,
"study1" = ages.data,
"study2" = test.data
)
dataset[,input$breytur, drop = F]
}, options=list(pageLength=10, searchDelay=500))
})
ui.R
shinyUI(navbarPage(img(src="logo.png"), theme="bootstrap.css", collapsible=T, windowTitle="My research",
tabPanel("Tables",
sidebarLayout(
sidebarPanel(
#The problem arises when I try to use this widget, I suspect it has something to do with me calling the output$dataset.
checkboxGroupInput("breytur", label="Hvaða dálka viltu sjá?", choices = names("output$dataset"), selected = names("output$dataset"))
),
mainPanel(
h2("Selected data"),
dataTableOutput("tafla.gogn")
)
)
))
))
当我 运行 应用程序时,出现错误:
收听 [已删除]
mapply(ids,选择,名称(选择),FUN = function(id,value,:
零长度输入不能与非零长度输入混合
mapply(ids,选择,名称(选择),FUN = function(id,value,:
零长度输入不能与非零长度输入混合
数据是从我应用程序的数据文件夹中的 .rda 文件加载的 data.frames。
我通过在服务器脚本中创建 CheckboxGroupInput 并呈现 UI 来做类似的事情。
[我想分享一种实现此目的的方法 - 懒得添加代码]
用代码回答:
Server.r :
ages.data <- load("data/ages.data.rda")
test.data <- load("data/test.data.rda")
data_sets <- c("ages.data","test.data")
shinyServer(function(input, output) {
output$choose_dataset <- renderUI({
selectInput("Dataset",label = "choose a dataset",as.list(data_sets))
})
output$choose_columns <- renderUI({
if(is.null(input$Dataset))
return()
dat <- get(input$Dataset)
colnames <- names(dat)
checkboxGroupInput("columns", "Choose columns",
choices = colnames,
selected = colnames)
})
ui.r
shinyUI(navbarPage(img(src="logo.png"), theme="bootstrap.css", collapsible=T, windowTitle="My research",
tabPanel("Tables",
sidebarLayout(
sidebarPanel(
uiOutput("choose_dataset"),
uiOutput("choose_columns")
),
我正在尝试在闪亮的应用程序中呈现数据 table。当我在没有任何条件参数的情况下通过它时,它显示得很好。当我尝试使显示的变量以来自 checkBoxGroup 小部件的输入为条件时出现问题。 这是我的代码的相关部分:
server.R
library(shiny)
library(ggplot2)
library(pander)
library(plyr)
load("data/ages.data.rda")
load("data/test.data.rda")
load("data/refine.data.rda")
shinyServer(function(input, output) {
output$tafla.gogn <- renderDataTable({
dataset <- switch(input$data,
"study1" = ages.data,
"study2" = test.data
)
dataset[,input$breytur, drop = F]
}, options=list(pageLength=10, searchDelay=500))
})
ui.R
shinyUI(navbarPage(img(src="logo.png"), theme="bootstrap.css", collapsible=T, windowTitle="My research",
tabPanel("Tables",
sidebarLayout(
sidebarPanel(
#The problem arises when I try to use this widget, I suspect it has something to do with me calling the output$dataset.
checkboxGroupInput("breytur", label="Hvaða dálka viltu sjá?", choices = names("output$dataset"), selected = names("output$dataset"))
),
mainPanel(
h2("Selected data"),
dataTableOutput("tafla.gogn")
)
)
))
))
当我 运行 应用程序时,出现错误: 收听 [已删除] mapply(ids,选择,名称(选择),FUN = function(id,value,: 零长度输入不能与非零长度输入混合 mapply(ids,选择,名称(选择),FUN = function(id,value,: 零长度输入不能与非零长度输入混合
数据是从我应用程序的数据文件夹中的 .rda 文件加载的 data.frames。
我通过在服务器脚本中创建 CheckboxGroupInput 并呈现 UI 来做类似的事情。 [我想分享一种实现此目的的方法 - 懒得添加代码] 用代码回答:
Server.r :
ages.data <- load("data/ages.data.rda")
test.data <- load("data/test.data.rda")
data_sets <- c("ages.data","test.data")
shinyServer(function(input, output) {
output$choose_dataset <- renderUI({
selectInput("Dataset",label = "choose a dataset",as.list(data_sets))
})
output$choose_columns <- renderUI({
if(is.null(input$Dataset))
return()
dat <- get(input$Dataset)
colnames <- names(dat)
checkboxGroupInput("columns", "Choose columns",
choices = colnames,
selected = colnames)
})
ui.r
shinyUI(navbarPage(img(src="logo.png"), theme="bootstrap.css", collapsible=T, windowTitle="My research",
tabPanel("Tables",
sidebarLayout(
sidebarPanel(
uiOutput("choose_dataset"),
uiOutput("choose_columns")
),