在Rshiny中,在renderPlot和renderText之间切换
首先,这里是我的Rshiny应用程序的一个精简框架,以及我正在尝试做的事情(但失败了):在Rshiny中,在renderPlot和renderText之间切换,r,ggplot2,shiny,R,Ggplot2,Shiny,首先,这里是我的Rshiny应用程序的一个精简框架,以及我正在尝试做的事情(但失败了): 我是不是离我要做的事情太远了?任何关于什么是错误的想法,以及我是否需要这种反应性的表达都将不胜感激 只能在反应式或呈现*函数中计算输入$..值 你可以做: ui <- shinyUI(fluidPage( titlePanel("Player Self-Centered Rating"), sidebarLayout( sidebarPanel( radioButtons(
我是不是离我要做的事情太远了?任何关于什么是错误的想法,以及我是否需要这种反应性的表达都将不胜感激 只能在
反应式
或呈现*
函数中计算输入$..
值
你可以做:
ui <- shinyUI(fluidPage(
titlePanel("Player Self-Centered Rating"),
sidebarLayout(
sidebarPanel(
radioButtons("radio", label = h3("Chart Type"),
choices = list("RadarPlot" = 1,
"Separate Plots" = 2,
"Top / Bottom 5 Table" = 3),
selected = 1)),
mainPanel(
plotOutput('radarPlot', width = 50),
textOutput("text2")
)
)
))
server <- shinyServer(function(input, output) {
output$radarPlot <- renderPlot({
if (input$radio %in% c(1,2)) {
ggplot(mtcars, aes(x = mpg, y = cyl, col = hp, fill = hp)) +
geom_bar(stat = "identity")}
}, height = 800, width = 900)
output$text2 <- renderText({
if (input$radio == 3) {
paste("print some text")}
})
})
shinyApp(ui,server)
ui
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.)
ui <- shinyUI(fluidPage(
titlePanel("Player Self-Centered Rating"),
sidebarLayout(
sidebarPanel(
radioButtons("radio", label = h3("Chart Type"),
choices = list("RadarPlot" = 1,
"Separate Plots" = 2,
"Top / Bottom 5 Table" = 3),
selected = 1)),
mainPanel(
plotOutput('radarPlot', width = 50),
textOutput("text2")
)
)
))
server <- shinyServer(function(input, output) {
output$radarPlot <- renderPlot({
if (input$radio %in% c(1,2)) {
ggplot(mtcars, aes(x = mpg, y = cyl, col = hp, fill = hp)) +
geom_bar(stat = "identity")}
}, height = 800, width = 900)
output$text2 <- renderText({
if (input$radio == 3) {
paste("print some text")}
})
})
shinyApp(ui,server)