我有一个闪亮的问题,我认为涉及JS,但我对JS的知识是不存在的。我希望能够从下面只打印一个箱图,具体取决于在同一个面板中按下的actionButton。我真的不知道我是否需要以这种方式做到这一点,所以任何帮助都表示赞赏。这是我的代码的摘要版本。
server.R
shinyServer(function(input, output, session) {
data_for_use <- reactiveValues(d=NULL)
observe({
input$DownloadButton
session$sendCustomMessage(type = 'testmessage',
message = list(a = "A"))
})
observe({
input$UploadButton
session$sendCustomMessage(type = 'testmessage',
message = list(a = "B"))
})
observeEvent(input$DownloadButton, {
GSEmRNA <- data.frame(first=c(3,5,7), second=c(10,11,54), third=c(26,12,5))
data_for_use$d <- GSEmRNA
})
observeEvent(input$UploadButton,{
GSEmRNA <- data.frame(first=c(1,6,9), second=c(5,5,5), third=c(17,6,18))
data_for_use$d <- GSEmRNA
})
output$BoxplotDatasetDownload <- renderPlot({
if (input$DownloadButton== 0) {return()}
else{
boxplot(data_for_use$d)}
})
output$BoxplotDatasetUpload <- renderPlot({
if (input$UploadButton== 0) {return()}
else{
boxplot(data_for_use$d)}
})
})
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Dataset Selection"),
# Sidebar with controls to select a dataset and specify the number
# of observations to view
sidebarPanel(
actionButton("DownloadButton","Download"),
actionButton("UploadButton","Upload"),
tabPanel(
tags$head(tags$script('Shiny.addCustomMessageHandler("testmessage",
function(message) {
print("The a variable is " + message.a);
}
);')))
),
mainPanel(
conditionalPanel(condition="input.DownloadButton && message.a == 'A'",
wellPanel(
column(8, plotOutput("BoxplotDatasetDownload")
)
)),
conditionalPanel(condition="input.UploadButton && message.a == 'B'",
wellPanel(
column(8, plotOutput("BoxplotDatasetUpload"))
))
)))
编辑:我尝试了类似这样的东西应该有效我想但是它没有。在ui.R我添加了
conditionalPanel(condition= "input.DownloadButton && input.UploadButton",
radioButtons("checkboxUpDown", label=h3("Choose which results to show"),
choices = list('Uploaded Data', 'Downloaded Data'), selected = NULL))
wellPanel("Input",
fluidRow(
conditionalPanel(condition= "input.UploadButton && !input.DownloadButton",
column(8, DT::dataTableOutput("dataTableUpload")
))),
fluidRow(
conditionalPanel(condition= "input.DownloadButton&& !input.UploadButton",
column(8,DT::dataTableOutput("dataTableDownload")))
),fluidRow(
conditionalPanel(condition= "input.DownloadButton&& input.UploadButton",
conditionalPanel(condition= "input.checkboxUpDown == 'Uploaded Data'",
column(8,DT::dataTableOutput("dataTableUpload"))),
conditionalPanel(condition= "input.checkboxUpDown == 'Downloaded Data'",
column(8,DT::dataTableOutput("dataTableDownload"))))
))