仅当数据加载到闪亮的应用程序中时才显示框 [英] Show box only when data is loaded in shiny app
本文介绍了仅当数据加载到闪亮的应用程序中时才显示框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经制作了一个闪亮的应用程序,我想在其中上传并显示在它旁边。由于我的数据量会很大,因此我将其设置为可滚动,并将其放入框中。
现在我希望仅在加载数据时显示该框。
我尝试了条件面板,但不起作用。
以下是代码
ui.R
library(shiny)
library(shinydashboard)
library(DT)
library(ggvis)
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = "Dashboard"),
dashboardSidebar(sidebarMenu(
menuItem("Data", tabName = "uploadData", icon = icon("table"))
)),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "gebIns"
),
# Second tab content
tabItem(tabName = "uploadData",
fluidPage(
fluidRow(
column(3,titlePanel("Upload Your Data"),
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
fluidRow(column(6,
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab=' '),
',')),
column(6,
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"'))),
selectInput('y', 'Y Variable', '---'),
numericInput('noOfVar', 'Number of Variables', 1),
actionButton("submit", "Submit")
),
column(9,
box(
title = "Data", width = NULL, status = "primary",
div(style = 'overflow-x: scroll', DT::dataTableOutput('contents'))
)
)
)
)
)
)
)
)
服务器.R
shinyServer(function(input, output, session) {
#load the data when the user inputs a file
theData <- reactive({
infile <- input$file1
if(is.null(infile))
return(NULL)
d <- read.csv(infile$datapath, header = T)
d
})
output$contents <- DT::renderDataTable({
data1 <- theData()
})
# dynamic variable names
observe({
data<-theData()
updateSelectInput(session, 'y', choices = names(data))
})
#gets the y variable name, will be used to change the plot legends
yVarName<-reactive({
input$y
})
})
推荐答案
您可以对数据使用renderUI
AND条件输出:
# ui.R
column(9,uiOutput("box"))
# server.R
output[["box"]] <- renderUI({
if(is.null(theData()))return()
box(
title = "Data", width = NULL, status = "primary",
div(style = 'overflow-x: scroll;', DT::dataTableOutput('contents'))
)
})
这篇关于仅当数据加载到闪亮的应用程序中时才显示框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文