Я новичок в использовании Shiny, я прочитал учебники и несколько вопросов о переполнении стека, но я думаю, что мне все еще не хватает какой-то ключевой концепции.
По сути, я хочу, чтобы пользователи сначала выбралиЗатем на основе этого набора данных они могут выбрать интересующий OTU. Затем я выведу график и, возможно, таблицу.
У меня есть синтаксис для выбора правильного набора данных, но как мне сгенерировать выборOTU, чтобы выбрать на основе этого?
Любая помощь приветствуется.
спасибо
ui <- fluidPage(
# Make a title to display in the app
titlePanel(" Exploring the Effect of Metarhizium on the Soil and Root Microbiome "),
# Make the Sidebar layout
sidebarLayout(
# Put in the sidebar all the input functions
sidebarPanel(
# drop down menu to select the dataset of interest
selectInput('dataset', 'dataset', names(abundance_tables)),
# drop down menu to select the OTU of interest
uiOutput("otu"),
#
br(),
# Add comment
p("For details on OTU identification please refer to the original publications")
),
# Put in the main panel of the layout the output functions
mainPanel(
plotOutput('plot')
# ,dataTableOutput("anova.tab")
)
)
)
server <- function(input, output){
# Return the requested dataset ----
datasetInput <- reactive({
switch(input$dataset)
})
#
dataset <- datasetInput()
# output otus to choose basaed on dataset selection
output$otu <- renderUI({
selectInput(inputId = "otu", label = "otu",
choices = colnames(dataset))
})
output$plot <- renderPlot({
#
dataset <- datasetInput()
otu <- input$otu
#dataset<-abundance_tables[[1]]
## melt and add sample metadata
df_annot<-merge(dataset,sample_metadata,by="row.names",all.x=T)
rownames(df_annot)<-df_annot[,1]
df_annot<-df_annot[,-1]
#
dfM<-melt(df_annot,id.vars = c("Location","Bean","Fungi","Insect"),value.name="abund")
# renaming Fungi level to metarhizium
levels(dfM$Fungi)<-c("Metarhizium","No Meta")
#
ggplot(subset(dfM, variable==otu),
aes(x=Insect,y=abund,fill=Fungi))+geom_boxplot()+facet_wrap(~Location,scales="free_y" )+
guides(fill=guide_legend("Metarhizium")) +
ggtitle(otu)
})
}
##
shinyApp(ui=ui,server=server)
Хорошо, я сделал некоторые исправления после некоторых ответов, но теперь получаю следующееошибка.
Listening on http://127.0.0.1:5684
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
Stack trace (innermost first):
41: .getReactiveEnvironment()$currentContext
40: .dependents$register
39: datasetInput
38: server [/Users/alisonwaller/Documents/Professional/Brock/Bidochka_Microbiome/shiny/Barelli_shiny.R#68]
1: runApp
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)