【发布时间】:2023-03-14 18:15:01
【问题描述】:
我对 R 编程(以及 StackOverflow 也是)完全陌生,并且正在使用 Shiny 包开发一个小型 R 项目(这似乎更容易并且符合我的要求)。现在我需要上传一个 .csv 文件,Shiny 已经为其提供了模板或以 ui.R 和 server.R 的形式说出代码。但我的问题是,sn-p Shiny 提供的代码包含一个浏览部分以及一个用于标题的复选框部分和用于选择分隔符(逗号、分号、制表符)和引号(无、双、单)的单选按钮。
。
现在我只需要浏览部分,而不需要标题、分隔符或引号,所以我修改了脚本,但单选按钮似乎没有。
# The code section starts here.
# Original Script provided by Shiny.
ui.R
library(shiny)
ui <- fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"')
),
mainPanel(
tableOutput('contents')
)
)
)
server.R file
library(shiny)
server <- function(input, output) {
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
})
}
shinyApp(ui=ui, server = server)
我能够删除标题复选框部分,如第二张图片所示
但无法移除单选框。请告知如何做到这一点。提前感谢大家。
【问题讨论】:
标签: r shiny data-science