摘要警告(如.numeric(粘贴(输入$to,";输入$to";)):通过强制使用R引入NAs
我对使用R的闪亮web应用程序非常陌生。我想根据我在浏览CSV文件时动态生成的checkboxGroupInput中的选择生成摘要。我的问题是,当我想从字符串转换为数字时,它会打印NA。 我正在上传我的两个文件,分别是ui.r和server.r。两天以来我一直在努力。如果有人帮助我,那将对我非常有益 如果我在我的代码中做了什么错误,那么请建议我正确的方法 ui.r摘要警告(如.numeric(粘贴(输入$to,";输入$to";)):通过强制使用R引入NAs,r,shiny,R,Shiny,我对使用R的闪亮web应用程序非常陌生。我想根据我在浏览CSV文件时动态生成的checkboxGroupInput中的选择生成摘要。我的问题是,当我想从字符串转换为数字时,它会打印NA。 我正在上传我的两个文件,分别是ui.r和server.r。两天以来我一直在努力。如果有人帮助我,那将对我非常有益 如果我在我的代码中做了什么错误,那么请建议我正确的方法 ui.r library(shiny) library(shinythemes) shinyUI(fluidPage( theme
library(shiny)
library(shinythemes)
shinyUI(fluidPage(
theme = shinytheme("cyborg"),
themeSelector(),
# Application title
titlePanel("Data Analytics and Visualization Dashboard"),
sidebarLayout(
sidebarPanel(
fileInput('datafile', 'Choose CSV file',accept=c('text/csv', 'text/comma-
separated-values,text/plain')),
h5("Max file size to upload is 5 MB."),
radioButtons("sep", "Seperator", choices = c(Comma = ',', semicolon = ';',
tab = "\t", space = " " )),
#checkboxInput("header", "Header?")
br(),
h4("Select columns from CSV"),
uiOutput("toCol"),
br(),
h4("Summary"),
textOutput("sum")
# tableOutput("disp")
),
mainPanel(
numericInput("obs", "Enter the number of rows to display:", 5),
tableOutput("input_file"),
plotOutput("p")
)
)
))
library(shiny)
shinyServer(function(input, output,session) {
#This function is repsonsible for reading a csv file
output$input_file <- renderTable({
file_to_read = input$datafile
if(is.null(file_to_read))
{
return()
}
read.csv(file_to_read$datapath, sep = input$sep, nrows = input$obs))
})
#This function is repsonsible for loading in the selected file
filedata <- reactive({
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath,nrows = input$obs)
})
#The following set of functions populate the column selectors
output$toCol <- renderUI({
df <-filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
checkboxGroupInput("to", "Columns",items)
})
observe({
# db <- gsub(",","",input$to)
# print(db)
# paste( intToUtf8(160), input$to, intToUtf8(160))
# print(summary(as.numeric(as.character( paste( " ", input$to, "
#"))))) })
print(summary(as.numeric( input$to) ))})
# output$sum <- renderPrint({
# summary(input$data.frame[,as.numeric(input$var)])
# })
# output$disp <- renderTable({
# input$to
# })
# output$summary1 <- renderPrint({
# sum <- as.numeric(as.character(input$to))
# summary(sum)
#})
})
server.r
library(shiny)
library(shinythemes)
shinyUI(fluidPage(
theme = shinytheme("cyborg"),
themeSelector(),
# Application title
titlePanel("Data Analytics and Visualization Dashboard"),
sidebarLayout(
sidebarPanel(
fileInput('datafile', 'Choose CSV file',accept=c('text/csv', 'text/comma-
separated-values,text/plain')),
h5("Max file size to upload is 5 MB."),
radioButtons("sep", "Seperator", choices = c(Comma = ',', semicolon = ';',
tab = "\t", space = " " )),
#checkboxInput("header", "Header?")
br(),
h4("Select columns from CSV"),
uiOutput("toCol"),
br(),
h4("Summary"),
textOutput("sum")
# tableOutput("disp")
),
mainPanel(
numericInput("obs", "Enter the number of rows to display:", 5),
tableOutput("input_file"),
plotOutput("p")
)
)
))
library(shiny)
shinyServer(function(input, output,session) {
#This function is repsonsible for reading a csv file
output$input_file <- renderTable({
file_to_read = input$datafile
if(is.null(file_to_read))
{
return()
}
read.csv(file_to_read$datapath, sep = input$sep, nrows = input$obs))
})
#This function is repsonsible for loading in the selected file
filedata <- reactive({
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath,nrows = input$obs)
})
#The following set of functions populate the column selectors
output$toCol <- renderUI({
df <-filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
checkboxGroupInput("to", "Columns",items)
})
observe({
# db <- gsub(",","",input$to)
# print(db)
# paste( intToUtf8(160), input$to, intToUtf8(160))
# print(summary(as.numeric(as.character( paste( " ", input$to, "
#"))))) })
print(summary(as.numeric( input$to) ))})
# output$sum <- renderPrint({
# summary(input$data.frame[,as.numeric(input$var)])
# })
# output$disp <- renderTable({
# input$to
# })
# output$summary1 <- renderPrint({
# sum <- as.numeric(as.character(input$to))
# summary(sum)
#})
})
库(闪亮)
shinyServer(功能(输入、输出、会话){
#此函数可用于读取csv文件
output$input\u file就像@coder所说的,在你的代码中没有这样一行摘要(如.numeric(粘贴(输入$to,“输入$to”)))
。我编辑了你的代码,所以所有未注释的行都不会出现,因为不需要显示它们
在您的示例中,您可以两次加载csv文件,这是可以避免的。
我将csv加载移到了被动模式。然后你可以在你闪亮的应用程序中访问加载的文件。我认为在你的打印(summary())
语句,您缺少数据,因为您只打印了输入$to
变量的摘要,该变量仅为文本,如果将其转换为数值,则会创建NA值
所以我重新安排了你的代码,我认为它的行为方式是你想要的
library(shiny)
library(shinythemes)
ui <- {shinyUI(fluidPage(
theme = shinytheme("cyborg"),
themeSelector(),
titlePanel("Data Analytics and Visualization Dashboard"),
sidebarLayout(
sidebarPanel(
fileInput('datafile', 'Choose CSV file',accept=c('text/csv', 'text/comma-
separated-values,text/plain')),
h5("Max file size to upload is 5 MB."),
radioButtons("sep", "Seperator", choices = c(Comma = ',', semicolon = ';',
tab = "\t", space = " " )),
br(),
h4("Select columns from CSV"),
uiOutput("toCol"),
br(),
h4("Summary"),
textOutput("sum")
),
mainPanel(
numericInput("obs", "Enter the number of rows to display:", 5),
tableOutput("input_file"),
verbatimTextOutput("summary"),
plotOutput("p")
)
)
))}
server <- shinyServer(function(input, output,session) {
#This function is repsonsible for loading and reading a csv file
filedata <- reactive({
req(input$datafile)
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath,nrows = input$obs, sep = input$sep)
})
output$input_file <- renderTable({
filedata()
})
#The following set of functions populate the column selectors
output$toCol <- renderUI({
df <- filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
checkboxGroupInput("to", "Columns",items)
})
output$summary <- renderPrint({
req(input$to)
data <- filedata()
print(summary(data[,input$to]))
})
})
shinyApp(ui, server)
库(闪亮)
图书馆(shinythemes)
ui这可能是一个起点,尽管我不建议将其用于高效应用程序,因为登录过程既不安全也不加密。它完全基于文本数据
但是你必须把用户界面放在服务器上,并根据登录状态呈现页面。所以有两个呈现界面,但只有一个服务器功能。我不知道你是否可以有两个不同的服务器功能并重定向它们。我想这一切都必须在一个服务器功能中
library(shiny)
username = "joe"
password = "joe123"
ui <- fluidPage(
uiOutput("ui")
)
server <- function(input, output, session) {
LOGGED <- reactiveValues(user = FALSE)
observeEvent(input$action, {
if ((input$name == username ) & (input$pass == password)) {
LOGGED$user = TRUE
} else {
LOGGED$user = FALSE
}
})
observe({
if (LOGGED$user == FALSE) {
output$ui <- renderUI({
tagList(
p(HTML("User is joe <br> and password is joe123")),
textInput("name", "Enter your username"),
passwordInput("pass", "Enter your password"),
actionButton("action", label = "Action")
)
})
} else if (LOGGED$user == TRUE) {
output$ui <- renderUI({
tagList(
h1("You are logged in.")
)
})
}
})
}
shinyApp(ui, server)
库(闪亮)
用户名=“乔”
password=“joe123”
ui我无法在您的代码中找到您的错误摘要行(如.numeric(粘贴(输入$to,“输入$to”))
。您的意思是打印(摘要(如.numeric(输入$to)))
?嗨,Heena,欢迎来到Stackoverflow。请回答有关如何共享一个闪亮示例的问题。checkboxGroupInput(“to”,“Columns”,items)
其中“to”是checkboxGroupInput的id。我在控制台中使用打印(摘要(作为.numeric(输入$to)))打印摘要
这样我就可以从checkboxGroupInput中获得用户选择的字段数。我想在检查checkboxGroupInput时动态生成摘要。@CoderHanks很多。但是我想在web浏览器中显示摘要。我不想在控制台中打印它。我如何使用在web浏览器中打印摘要ode>event?@SegawWhy你需要一个观察,为什么不直接放在renderPrint函数中?我会更新我的代码,这样它就会在网上打印出来。非常感谢,先生。@SegayYou不客气。如果这回答了你的问题,你能把它标记为选中吗?是的。我选中了。先生,我还上传了第二个问题。你想帮我吗?如何重拨如果登录成功,从一个用户界面直接到另一个用户界面?也许可以帮助您