gpt4 book ai didi

r - 仅在 Shiny 的应用程序中加载数据时显示框

转载 作者:行者123 更新时间:2023-12-01 11:24:19 24 4
gpt4 key购买 nike

我制作了一个 Shiny 的应用程序,我想在其中上传并在它旁边显示它。因为我的数据会很大,所以我把它做成了可滚动的并放在一个盒子里。

现在我只想在加载数据时显示该框。

enter image description here

我尝试了条件面板,但没有成功。

这里是代码

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='\t'),
',')),
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 和条件输出:

# 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'))
)

})

关于r - 仅在 Shiny 的应用程序中加载数据时显示框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38931289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com