library(shiny)
library(shinydashboard)
library(leaflet)
library(data.table)
library(ggplot2)
library(usl)
ui <- pageWithSidebar(
headerPanel("CSV Viewer"),
sidebarPanel(
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("xaxisGrp","X-Axis:", c("1"="1","2"="2"))),
column(6,checkboxGroupInput("yaxisGrp","Y-axis:", c("1"="1","2"="2")))
),
radioButtons('sep', 'Separator',
c(Comma=',', Semicolon=';',Tab='\t'), ','),
radioButtons('quote', 'Quote',
c(None='','Double Quote'='"','Single Quote'="'"),'"'),
uiOutput("choose_columns")
),
mainPanel(
tabsetPanel(
tabPanel("Data", tableOutput('contents')),
tabPanel("Plot",plotOutput("plot")),
tabPanel("Summary",uiOutput("summary"))
)
)
)
####server
server <- function(input, output,session) {
dsnames <- c()
u<-
data_set <- reactive({
inFile <- input$file1
data(specsdm91)
if (is.null(inFile))
return(specsdm91)
data_set<-read.csv(inFile$datapath, header=input$header,
sep=input$sep, quote=input$quote)
})
output$contents <- renderTable({data_set()})
observe({
dsnames <- names(data_set())
cb_options <- list()
cb_options[ dsnames] <- dsnames
updateRadioButtons(session, "xaxisGrp",
label = "X-Axis",
choices = cb_options,
selected = "")
updateCheckboxGroupInput(session, "yaxisGrp",
label = "Y-Axis",
choices = cb_options,
selected = "")
})
output$choose_dataset <- renderUI({
selectInput("dataset", "Data set", as.list(data_sets))
})
usl.model <- reactive({
df <- data_set()
# print(df)
df2 <- df[,c(input$xaxisGrp, input$yaxisGrp)]
#gp <- NULL
if (!is.null(df)){
xv <- input$xaxisGrp
yv <- input$yaxisGrp
print(xv)
print(yv)
if (!is.null(xv) & !is.null(yv)){
if (sum(xv %in% names(df))>0){ # supress error when changing files
usl.model <- usl(as.formula(paste(yv, '~', xv)), data = df)
return(usl.model())
}
}
}
#return(gp)
}
)
##plot
output$plot = renderPlot({
plot(usl.model())
} )
##
# output$summary <- renderUI({
# summary(usl.model())
#})
##
output$choose_columns <- renderUI({
if(is.null(input$dataset))
return()
colnames <- names(contents)
checkboxGroupInput("columns", "Choose columns",
choices = colnames,
selected = colnames)
})
}
shinyApp(ui, server)
如你所见,我打印了df。有什么想法吗?
答案 0 :(得分:2)
编辑:请提供可重现的数据示例。没有它,很难想象数据类型是什么。总的来说,我认为你可能有两个问题:
gp
?您需要不返回gp
,而是usl.model
renderUI
未传递UI对象(即输出函数不知道该怎么做)。 您的问题是usl.model
实际上并未在任何地方保存,因为它在renderPlot
内被调用,而usl.model
仅返回该情节。由于您希望usl.model
被两个函数使用,因此您应采用以下方法之一。
为usl.model <- reactive({
# some calculations probably ending in
usl.model <- usl(as.formula(paste(yv, '~', xv)), data = df)
usl.model
})
定义反应函数,并在两个输出函数中引用它。
usl.model()
这允许您将模型输出引用为output$plot <- renderPlot( plot(usl.model(), add=TRUE) )
(括号是重要的!),例如
usl.model
创建一个reactiveValues()变量来存储您在绘图函数中计算的usl.model <- reactiveValues(data = NULL)
output$plot = renderPlot({
# some calculations probably ending in
usl.model$data <- usl(as.formula(paste(yv, '~', xv)), data = df)
})
。
usl.model$data
然后,您可以在subkeys = key_schedule(NUMBER_OF_ROUNDS)
matrix = binary_to_matrix(input_block)
matrix = add_round_key(matrix, subkeys[0])
for round in xrange(1, NUMBER_OF_ROUNDS):
matrix = sub_bytes(matrix)
matrix = shift_rows(matrix)
matrix = mix_columns(matrix)
matrix = add_round_key(matrix, subkeys[round])
matrix = sub_bytes(matrix)
matrix = shift_rows(matrix)
matrix = add_round_key(matrix, subkeys[-1])
方法二可能更糟,因为它需要首先运行绘图功能。