when i execute my code i have only the the siderbarPanel in my application,and when i choose the state nothing to show. the probleme that i don't have any error in my code to correct in
My data:
total.death=c(48, 24, 12, 22)
total.recovred=c(12, 22, 78, 21)
total.cases=c(553, 226, 742, 370)
State=c ('USA', 'Belgium', 'France','Russia')
df2 = data.frame(State,total.cases,total.recovered,total.death)
My code:
library(shiny)
library(plotly)
library(RColorBrewer)
ui=fluidPage(
selectInput("select", label = h3("Select box"),
choices = df2$State,
selected = 1),
hr(),
fluidRow(column(3, verbatimTextOutput("value"))),
mainPanel(
textOutput("text1"),
plotOutput("mypie")
))
s=function(input, output) {
output$text1 <- renderText({
txt = as.character(input$select)
paste("text is", txt)
})
output$mypie <- renderPlot(
{labels=c("unrecovered","recovered","death")
S=filter(df2,df2[1]==as.character(input$select) )
S=c(S[2],S[3],S[4])
plot_ly(labels = ~labels,
values = ~S, type = 'pie',
marker = list(colors = brewer.pal(7,"Spectral")))
})
}
shinyApp(ui=ui,server = s)
Try using plotlyOutput
and renderPlotly
. See below for working version. Minor modifications made to spelling, case-sensitive names, etc.
Edit : This includes S = unlist(S[-1])
for plotting as mentioned in comments.
total.death=c(48, 24, 12, 22)
total.recovered=c(12, 22, 78, 21)
total.cases=c(553, 226, 742, 370)
State=c ('USA', 'Belgium', 'France','Russia')
df2 = data.frame(State,total.cases,total.recovered,total.death)
library(shiny)
library(plotly)
library(RColorBrewer)
ui=fluidPage(
selectInput("select", label = h3("Select box"),
choices = df2$State,
selected = 1),
hr(),
fluidRow(column(3, verbatimTextOutput("value"))),
mainPanel(
textOutput("text1"),
plotlyOutput("mypie")
)
)
s=function(input, output) {
output$text1 <- renderText({
txt = as.character(input$select)
paste("text is", txt)
})
output$mypie <- renderPlotly({
labels=c("unrecovered","recovered","death")
S=filter(df2, df2$State==as.character(input$select))
S = unlist(S[-1])
plot_ly(labels = ~labels,
values = ~S, type = 'pie',
marker = list(colors = brewer.pal(7,"Spectral")))
})
}
shinyApp(ui=ui,server = s)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.