我是R-shiny应用程序的新手,我的应用程序非常简单.它有两个选项卡,在第一个,我上传一个文件,如csv,然后在第二个选项卡中,我选择将要绘制的列,我的解决方案分散在几个例子,每个都与我的不一样,我想要上传的数据集有待观察,并且可以在所有功能中使用,而不仅仅是在上传时.
我的服务器.R
library(shiny)
shinyServer(function(input, output) {
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
})
output$MyPlot <- renderPlot({
x <- contents()$contents[, c(input$xcol, input$ycol)]
bins <- nrow(contents())
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
Run Code Online (Sandbox Code Playgroud)
ui.R
library(shiny)
library(datasets)
shinyUI(fluidPage(
titlePanel("Column Plot"),
tabsetPanel(
tabPanel("Upload File",
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv'))
),
mainPanel(
tableOutput('contents')
)
)
),
tabPanel("First Type",
pageWithSidebar(
headerPanel('My First Plot'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(content)), …Run Code Online (Sandbox Code Playgroud) 设f和g是两个单参数的函数.f后面的组合物g被定义为功能x \mapsto f(g(x)).
说该程序compose实现了组合.例如,如果inc是一个向其参数添加1并square对其参数((compose square inc) 6)
求平方的过程,则
求值为49.
解决方案很简单.它看起来非常像它的数学模拟:
(define (compose f g)
(lambda (x) (f (g x))))
Let's test:
(define (square x) (* x x))
(define (inc x) (+ x 1))
((compose square inc) 6)
Output:
49
Run Code Online (Sandbox Code Playgroud)
如何使用C++实现组合?有可能写出这样的参数并让函数实现自己吗?